Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- \_\
- (_**)
- __) #_
- ( )...() => HI
- || | |I|
- || | |()__/
- /\(___)
- */
- #include<bits/stdc++.h>
- using namespace std;
- using lli = int64_t;
- void min_max_sum(int n,vector<int> nums,int k){
- int l = 0,r = 0;
- int min_sum = INT_MAX,max_sum = INT_MIN,sum = 0;
- while(r < n){
- while(r - l < k and r < n){
- sum += nums[r++];
- }
- min_sum = min(min_sum,sum);
- max_sum = max(max_sum,sum);
- if(r - l == k){
- sum -= nums[l++];
- }
- }
- cout << min_sum << " " << max_sum << "\n";
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n,k;
- cin >> n >> k;
- vector<int> nums(n);
- for(int i = 0;i < n; i++){
- cin >> nums[i];
- }
- //generate min max sum of subarray length k (distinct array);
- min_max_sum(n,nums,k);
- }
Add Comment
Please, Sign In to add comment