View Code of Problem 2222

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
using namespace std;

typedef unsigned long long ULL;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);

    int a[10005];
    int n,k;
    while(cin>>n>>k&&n>=0)
    {
        for(int i=0;i<=n;i++)
            cin>>a[i];
        for(int i=n;i>=k;i--)
            if(a[i])
            {
                a[i-k]=a[i-k]-a[i];
                a[i]=0;
            }
        while(n>=0&&!a[n])
            n--;
        if(n<0)
            printf("0");
        for(int i=0;i<=n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 2222