Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. const ll M = 1000002;
  7. ll n,m;
  8. ll tab[M];
  9. ll pref[M];
  10. pair<ll,ll> para[M];
  11. vector<ll> wyn;
  12. ll wynik;
  13. int main()
  14. {
  15. cin >> n >> m;
  16. for(ll i=1; i<=n; i++)
  17. {
  18.     cin >> tab[i];
  19.     pref[i]=pref[i-1] + tab[i];
  20.     para[i].first = pref[i];
  21.     para[i].second = i;
  22. }
  23.  
  24. sort(para, para+n);
  25.  
  26.  
  27.  
  28. for(ll i=1; i<=n; i++)
  29. {
  30.     for(ll j=1; para[j].first - para[i].first<=m; j++)
  31.     {
  32.         if(para[j].first - para[i].first == m) wyn.push_back(para[j].second - para[i].second);
  33.     }
  34. }
  35.  
  36. for(ll i=0; i<wyn.size(); i++)
  37. {
  38.  
  39.     wynik = max (wynik, wyn[i]);
  40. }
  41.  
  42. if(wynik == 0) cout << "BRAK";
  43. else cout << wynik;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement