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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.