84782024-01-17 12:50:14anonFolyóparti telkek (40 pont)cpp17Accepted 40/4019ms6340 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
int main() {
    FastIO;
    ll i, ans, N, P;
    cin >> N >> P;
    vector<ll> prices(N);
    for(i = 0; i < N; i++)
        cin >> prices[i];
    vector<ll> acc(N);
    acc[0] = prices[0];
    for(i = 1; i < N; i++)
        acc[i] = acc[i - 1] + prices[i];
    if(P >= acc.back()) {
        cout << N << '\n';
        return 0;
    }
    ans = 0;
    for(i = 0; i < N; i++)
        ans = max(ans, i - (lower_bound(all(acc), acc[i] - P) - acc.begin()));
    cout << ans << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1832 KiB
2Accepted0/019ms5048 KiB
3Accepted2/23ms2228 KiB
4Accepted2/23ms2444 KiB
5Accepted2/23ms2656 KiB
6Accepted2/23ms3012 KiB
7Accepted2/23ms2896 KiB
8Accepted3/33ms3268 KiB
9Accepted3/33ms3244 KiB
10Accepted3/33ms3144 KiB
11Accepted3/33ms3160 KiB
12Accepted3/310ms4440 KiB
13Accepted3/313ms4900 KiB
14Accepted3/313ms5224 KiB
15Accepted3/316ms6220 KiB
16Accepted3/316ms6196 KiB
17Accepted3/317ms6340 KiB