Go: package main

import "fmt"

func main() {

	for true {
		var n, k int
		fmt.Scan(&n, &k)

		if n == 0 && k == 0 {
			return
		}
		
		a := make([]int, n)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if i == 0 {
				ans[i] = a[i]
			} else {
				ans[i] = ans[i-1] + a[i]
			}
		}
		max := 0
		for i := k; i < n; i++ {
			t := ans[i] - ans[i-k]
			if max < t {
				max = t
			}
		}
		fmt.Println(max)
	}
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	long long int ans;
	int num[100001];
	int n,k;
	int a;
	ans=0;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0 && k==0)break;
		ans=0;
		for(a=0;a<n;a++)scanf("%d",&num[a]);
		for(a=0;a<k;a++){
			ans+=num[a];
		}
		for(a=k;a<n;a++){
			ans=max(ans,ans+num[a]-num[a-k]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;


int main(){
    vector<int> inp;
    int n, k, input;
    cin >> n >> k;

    for (int i = 0; i < n; i++){
	cin >> input;
	inp.push_back(input);
    }
    
    int right = inp.size(), left = 0, sum = 0;
    for (int i = 0; i < inp.size(); i++) sum += inp[i];

    while (right - left >= k){
	if (inp[right] > inp[left]){
	    sum -= inp[left];
	    left++;
	}
	else {
	    sum -= inp[right];
	    right--;
	}
    }
    
    cout << sum << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>

#define rep(i, a, b) for(int i = (a); (i) < (b); i++)

using namespace std;

int main() {
	int n, k;
	vector<int> num;
	int tmp;

	while(cin >> n >> k, n) {
		rep(i, 0, n) {
			cin >> tmp;
			num.push_back(tmp);
		}

		int s = 0;
		rep(i, 0, k) {
			s += num[i];
		}

		rep(i, 0, k-1) {
			s = max(s - num[i] + num[i+k], s);
		}
		
		cout << s << endl;
	}

	return 0;
}

C++: /**********************************************

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

last updated: 2013-07-10@17:04

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){
                
                int n=0;
                int k=0;
                int total=0, answer=0;
               

                cin >> n >> k;
                if(n==0 && k==0)break;
                vector <int> data(n);
                
                for(int i=0; i<n; i++){
                        cin >> data[i];
                        //cout << "data[i]="<< data[i]<<endl;
                }

                for(int j=0; j<n-k+1; j++){
                        
                        if( j == 0){
                                for(int i=0; i<k; i++){
                                        total = total + data[j+i];
                                }
                                //cout << "subtotal1="<<total<<endl;
                        }else{
                                
                                total = total - data[j-1] + data[j+k-1];
                                //cout << "subtotal2="<<total<<endl;
                        }
                        //cout << "answer="<<answer<<"subtotal="<<total<<endl;
                        if( total > answer ){
                                answer = total;
                        }
                        //cout << "answer="<<answer<<endl;
                }
                
                cout << answer << endl;
                
        }

        return 0;

}

C++: #include <iostream>
using namespace std;

int main() {
	while (1){
		int n, k;
		cin >> n >> k;

		if (n == 0 && k == 0){ break; }
		else{
			int i, inp;
			int *a;
			a = new int[n];

			for (i = 0; i<n; i++){
				cin >> inp;
				a[i] = inp;
			}

			int sum1 = 0, sum2 = 0, max = 0;

			for (i = 0; i<k; i++){ sum1 += a[i]; }
			max = sum1;

			for (i = k; i<n; i++){
				sum2 = sum1 + a[i] - a[i - k];
				if (sum2>max){ max=sum2; }
				sum1 = sum2;
			}

			cout << max << endl;

			delete[] a;
		}
	}
	return 0;
}

C++: #include <iostream>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(void){
	int n,k;
	while (cin>>n>>k,n||k) {
		int a[100000];
		int sum=0;
		int m=0;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<k;i++)sum+=a[i];
		m=sum;
		for(int i=k+1;i<n;i++){
			sum-=a[i-k-1];
			sum+=a[k];
			m=MAX(sum,m);
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  while(true){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n==0&&k==0) return 0;
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    int sum = 0,ans = 0;
    for(int i=0;i+k<=n;i++){
      if(i==0){
        for(int j=0;j<k;j++) sum += a[i+j];
        ans = sum;
      }else{
        sum = sum - a[i-1] + a[i+k-1];
        ans = max(ans,sum);
      }
    }
    printf("%d\n",ans);
  }
}

C++: #include<stdio.h>
int main(void){
	int n,k,a[100000],i,j,sum,max;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)break;
		for(i=0;i<n;i++) scanf("%d",&a[i]);
		max=-1;
		for(i=0;i<n;i++){
			sum=0;
			if(i+k<n){
				for(j=i;j<i+k;j++) sum+=a[j];
			}
			if(max<sum) max=sum;
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, k, a[100001];
    int pre = 0;
    int max = 0;

    cin >> n >> k;
    while (n != 0 && k != 0) {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < k; i++) {
        pre += a[i];
    }

    for (int i = 1; i <= n-k; i++) {
        pre = pre - a[i-1] + a[i+k-1];
        if (pre > max) {
            max = pre;
        }
    }

    cout << max << endl;
    cin >> n >> k;
    max = 0;
    pre = 0;
    }
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

int n, k ,i = 0, a[100000];
long long int b[100000];
long long int result[100][2];

int main()
{
	for (;; i++)
	{
		cin >> n >> k;
		if (n == 0)
		{
			break;
		}

		for (int p = 0; p < n; p++)
		{
			cin >> a[p];
		}

		for (int p = 0; p < n - k; p++)
		{
			for (int q = 0; q < k; q++)
			{
				result[i][0] += a[p + q];
			}
			result[i][1] = max(result[i][0], result[i][1]);
			result[i][0] = 0;
		}
	}
	for (int p = 0; p < i; p++)
	{
		cout << result[p][1] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int n, k;
    while(cin >> n >> k) {
        if(n == 0) break;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];

        vector<int> cs(n+1, 0);
        for(int i = 1; i < n+1; i++) {
            cs[i] = cs[i-1];
            cs[i] += a[i-1];
        }

        int ans = (-1) * INF;
        for(int i = 0; i < n+1-k; i++) {
            ans = max(ans, cs[i+k] - cs[i]);
        }
        cout << ans << endl;
    }

}

C++: #include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	while(1){
		int n,k,b[100100]={},sum[100100]={};
		cin>>n>>k;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>b[i];
		}
		for(int i=0;i<(n-k+1);i++){
			for(int j=0;j<k;j++){
				sum[i]+=b[j+i];
			}
		}
		sort(sum,sum+(n-k+1), greater<int>()); 
		cout<<sum[0]<<endl;
	}
	return 0;
}