Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //{ Driver Code Starts
- #include<bits/stdc++.h>
- using namespace std;
- // } Driver Code Ends
- class Solution{
- public:
- long long maximumSumSubarray(int K, vector<int> &v , int N){
- long arr[N+1] = {};
- for(int i=1; i<=N; i++){
- arr[i] = arr[i-1] + v[i-1];
- }
- long count = 0;
- for(int i=1, j=K; j<=N; i++, j++){
- long x = arr[j] - arr[i-1];
- if(x>count){
- count = x;
- }
- }
- return count;
- }
- };
- //{ Driver Code Starts.
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int N,K;
- cin >> N >> K;;
- vector<int>Arr;
- for(int i=0;i<N;++i){
- int x;
- cin>>x;
- Arr.push_back(x);
- }
- Solution ob;
- cout << ob.maximumSumSubarray(K,Arr,N) << endl;
- }
- return 0;
- }
- // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement