Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<fstream>
- #include<vector>
- #define long long long
- #define nln '\n'
- const long N = 1e5+10;
- using namespace std;
- // Global variables: f1, f2, n, p, a, tol
- fstream f1, f2;
- inline void openf()
- {
- f1.open("nkmaxseq.inp", ios:: in);
- f2.open("nkmaxseq.out", ios:: out);
- }
- inline void closef()
- {
- f1.close();
- f2.close();
- }
- long p, n;
- vector<long> a;
- vector<long> tol;
- void data()
- {
- f1.tie(0)->sync_with_stdio(0);
- f2.tie(0)->sync_with_stdio(0);
- //cin.tie(0)->sync_with_stdio(0);
- cin >> n >> p;
- for (long i = 0; i != n; ++i)
- {
- long x;
- cin >> x;
- a.push_back(x);
- }
- tol.resize(n, 0);
- tol[0] = a[0];
- for (long i = 1; i != n; ++i)
- tol[i] = tol[i-1] + a[i];
- }
- long sum(long i, long j)
- {
- return (tol[j]-tol[i-1]);
- }
- bool check(long len)
- {
- for (long i = 0; i+len-1 != n; ++i)
- if (sum(i, i+len-1) >= p)
- return 1;
- return 0;
- }
- long ans = -1;
- void process()
- {
- for (long len = n; len >= 1; --len)
- if (check(len))
- {
- ans = len;
- return;
- }
- }
- void view()
- {
- cout << ans << nln;
- }
- int main()
- {
- openf();
- data();
- process();
- view();
- closef();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment