Codeforces 363B - Fence Solution
Solution in C++:
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- main()
- {
- int n,k,i,mn,ind,tm=0;
- cin>>n>>k;
- {
- int a[n+1];
- for(i=0; i<n; i++)
- cin>>a[i];
- for(i=0;i<k;i++)
- tm+=a[i];
- mn=tm;
- ind=1;
- for(i=1; i<=n-k; i++)
- {
- tm-=a[i-1];
- tm+=a[i+k-1];
- if(mn>tm)
- {
- mn=tm;
- ind=i+1;
- }
- }
- cout<<ind<<endl;
- }
- }
No comments