Advertisement
ipilot

Problem J

Oct 26th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <stdio.h>
  4. #include <memory.h>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. #define mp make_pair
  12. #define pb push_back
  13. #define _(a,b) memset( (a), b, sizeof( a ) )
  14. #define all(a) a.begin(), a.end()
  15. #define sz(a) (int)a.size()
  16. #define foreach(struct, iterator) for (iterator=struct.begin(); iterator != struct.end(); ++iterator)
  17. #define forn(i, n) for (i=0; i < n; i++)
  18. #define forab(i, a, b) for (i=a; i < b; i++)
  19.  
  20. void prepare(string s)
  21. {
  22. #ifdef _DEBUG
  23.     freopen("input.txt", "r", stdin);
  24. #else
  25.     if (sz(s) != 0)
  26.     {
  27.         freopen((s + ".in").c_str(),"r",stdin);
  28.         freopen((s + ".out").c_str(),"w",stdout);
  29.     }
  30. #endif
  31. }
  32.  
  33. int seq[100000];
  34. vector <int> ss;
  35.  
  36. vector <int> chsum(int x, int n)
  37. {
  38.     int i;
  39.     vector <int> s;
  40.     s.pb(seq[0]);
  41.     forab(i, 1, x) s[0]+=seq[i];
  42.     forab(i, x, n) s.pb(s.back()-seq[i-x]+seq[i]);
  43.     return s;
  44. }
  45.  
  46. int main()
  47. {
  48.     int n, s;
  49.     bool f;
  50.     prepare("");
  51.     while (cin >> n)
  52.     {
  53.         int i, k, l, r, x;
  54.         cin >> s;
  55.         forn(i, n) cin >> seq[i];
  56.         l=1;
  57.         r=n;
  58.         while (l < r)
  59.         {
  60.             x=(l+r)/2;
  61.             ss=chsum(x, n);
  62.             k=*max_element(all(ss));
  63.             f=(k < s);
  64.             if (f) l=x+1;
  65.             else r=x;
  66.         }
  67.         cout << l << endl;
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement