16452022-12-01 11:40:341478Leggyorsabb pénzkeresés (50)cpp11Accepted 50/5035ms5548 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

const int nMax = 100000;
vector<int> prefixSum(nMax + 1);

int binarySearch(int i, int j, int val)
{
    int m;
    while (i <= j)
    {
        m = i + (j - i) / 2;
        if (prefixSum[m] == val)
            return m;
        else if (prefixSum[m] > val)
        {
            j = m - 1;
        }
        else
        {
            i = m + 1;
        }
    }
    return j;
}

int main()
{

    int n;
    cin >> n;

    int p;
    cin >> p;

    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        prefixSum[i] = prefixSum[i - 1] + a;
    }

    int ans = nMax;
    for (int i = n; i >= 1; i--)
    {

        int val = prefixSum[i] - p;
        if (val >= 0)
        {
            int j = binarySearch(0, i - 1, val);
            ans = min(ans, i - j);
        }
    }
    cout << ans;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2388 KiB
2Accepted0/035ms2556 KiB
3Accepted2/23ms2788 KiB
4Accepted2/23ms2988 KiB
5Accepted2/23ms3344 KiB
6Accepted2/26ms3416 KiB
7Accepted2/26ms3512 KiB
8Accepted2/26ms3728 KiB
9Accepted2/26ms3812 KiB
10Accepted2/26ms3772 KiB
11Accepted2/234ms4004 KiB
12Accepted2/235ms4124 KiB
13Accepted2/235ms4092 KiB
14Accepted2/235ms4216 KiB
15Accepted2/235ms4444 KiB
16Accepted2/235ms4364 KiB
17Accepted2/235ms4556 KiB
18Accepted2/235ms4680 KiB
19Accepted2/235ms4744 KiB
20Accepted2/235ms4872 KiB
21Accepted2/235ms4968 KiB
22Accepted2/235ms5096 KiB
23Accepted2/235ms5080 KiB
24Accepted2/235ms5172 KiB
25Accepted2/235ms5300 KiB
26Accepted2/235ms5476 KiB
27Accepted2/235ms5548 KiB