Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e5 + 100;
- int n, l;
- int a[maxn];
- ll pref[maxn];
- ll query(int i, int j) {
- if(i == 0) {
- return pref[j];
- }
- return pref[j] - pref[i - 1];
- }
- bool check(ll frogs) {
- for(int i = 0; i < n; i++) {
- if(i + l - 1 >= n) {
- return true;
- }
- if(query(i, i + l - 1) < frogs) {
- return false;
- }
- }
- return true;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> l;
- n--;
- ll sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- sum += a[i];
- pref[i] = sum;
- }
- ll L = 0, R = 2e9;
- ll res= 0 ;
- while(L <= R) {
- ll mid = (L + R) / 2;
- if(check(mid)) {
- res = max(res, mid);
- L = mid + 1;
- }
- else {
- R = mid - 1;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement