P19998 [GeeksforGeeks] Pick values4112
普及-
题目描述

Given an array arr[] of N positive integers. Select values from the array such that their sum is minimum. You must pick at least 1 value from each group of 4 consecutive elements.
Example 1:
Input:
N = 5
Arr[] = {1, 2, 3, 1, 2}
Output: 1
Explanation: There are 2 groups of 4
in the given array. The 1st group is
[1 2 3 1] and 2nd is [2 3 1 2].
Selecting the 4th element in the
array will give the least sum as
it belongs to both groups.
Example 2:
Input:
N = 6
Arr[] = {8, 6, 9, 10, 6, 7}
Output: 9
Explanation: There are 3 groups of 4
consecutive elements. 9 at index 2
is the smallest element that is
present in all 3 groups.
Your Task:
You don't need to read input or print anything. Your task is to complete the function pickValues() which takes the array of integers arr[] and its size n as input parameters and returns an integer denoting the minimum sum.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ Arr[i] ≤ 10^{3}

输入格式

见题面

输出格式

见题面

样例输入
N = 5 Arr[] = {1, 2, 3, 1, 2}
样例输出
1