363B Codeforces - Fence


363B Codeforces - Fence






Solution in C++


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
typedef long long int lli;

lli n,m,sol,val,acc,bst=-1;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    lli nn[n];
    for(int i=0;i<n;i++)
    {
        cin>>nn[i];
        if(i<m)val+=nn[i];
        else if(i>=m)
        {
            if(val<=bst || bst==-1)sol=i+1,bst=val;
            val=val-nn[i-m]+nn[i];
        }
    }
    if(val<=bst || bst==-1)sol=n+1;
    cout<<sol-m;
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق