Codeforces 363B - Fence Solution

Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh 

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. main()
  4. {
  5.  
  6. int n,k,i,mn,ind,tm=0;
  7. cin>>n>>k;
  8. {
  9. int a[n+1];
  10. for(i=0; i<n; i++)
  11. cin>>a[i];
  12. for(i=0;i<k;i++)
  13. tm+=a[i];
  14. mn=tm;
  15. ind=1;
  16. for(i=1; i<=n-k; i++)
  17. {
  18. tm-=a[i-1];
  19. tm+=a[i+k-1];
  20. if(mn>tm)
  21. {
  22. mn=tm;
  23. ind=i+1;
  24. }
  25.  
  26. }
  27. cout<<ind<<endl;
  28. }
  29. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.