# MAXSTACK - Editorial

Author: rocknot
Tester: root_rvl
Editorialist:rocknot

EASY

# PREREQUISITES:

Implementation ,queue.

# PROBLEM:

Aditya is good at making posters so he participated at poster making contest at his college. His poster stood out among the rest because it was different and appealing, So he easily won the competition. Prices for this competition were unique, and as a winner he was given a chance to select K prices of his choice .So he was given list of prices, but there is one problem he can only select consecutive prices. Aditya is clever and decided to make most of it. You are given an array of N integers denoting value of each price and you need to select K consecutive prices such that the total value he gets is maximum.

# EXPLANATION:

You just need to add K elements to queue and then Keep adding from K+1 element till Nth element and make sure that length of queue is equal to K and you just need to keep track of sum of the maximum value of queue.

# SOLUTIONS:

Solution
``````#include <bits/stdc++.h>
using namespace std;

int main(){
int T;
cin>>T;
while(T--){
int N,K;
cin>>N>>K;
int arr[N];
for(int i=0;i<N;i++){
cin>>arr[i];
}
int sum=0,max=0;
for(int i=0;i<K;i++){
sum+=arr[i];
}
max=sum;
int temp=0;
for(int i=K;i<N;i++){
sum-=arr[temp];
sum+=arr[i];
temp++;
if(sum>max){
max=sum;
}
}
cout<<max<<endl;
}
return 0;
``````

}
{"ft_lang_label":"__label__en","ft_lang_prob":0.8853317,"math_prob":0.93307585,"size":1341,"snap":"2022-05-2022-21","text_gpt3_token_len":358,"char_repetition_ratio":0.08825729,"word_repetition_ratio":0.0,"special_character_ratio":0.26398212,"punctuation_ratio":0.15511551,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98829424,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-27T00:38:29Z\",\"WARC-Record-ID\":\"<urn:uuid:9ef23ba2-55a5-4f35-8e11-52dd30507506>\",\"Content-Length\":\"12889\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:191e1fd2-61e8-4488-ac2d-189b6d219be7>\",\"WARC-Concurrent-To\":\"<urn:uuid:e030b510-ceba-4a1e-8905-ad85437c0d87>\",\"WARC-IP-Address\":\"3.231.242.28\",\"WARC-Target-URI\":\"https://discuss.codechef.com/t/maxstack-editorial/98878\",\"WARC-Payload-Digest\":\"sha1:VQCGZ5HS725KGZ5TUZ5FS7F4O7HKUM2M\",\"WARC-Block-Digest\":\"sha1:E6KGP4BB54MOBQIY4VYEWTXB4GFRBI4L\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662627464.60_warc_CC-MAIN-20220526224902-20220527014902-00303.warc.gz\"}"}