16452022-12-01 11:40:341478Leggyorsabb pénzkeresés (50)cpp11Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2388 KiB
2Elfogadva0/035ms2556 KiB
3Elfogadva2/23ms2788 KiB
4Elfogadva2/23ms2988 KiB
5Elfogadva2/23ms3344 KiB
6Elfogadva2/26ms3416 KiB
7Elfogadva2/26ms3512 KiB
8Elfogadva2/26ms3728 KiB
9Elfogadva2/26ms3812 KiB
10Elfogadva2/26ms3772 KiB
11Elfogadva2/234ms4004 KiB
12Elfogadva2/235ms4124 KiB
13Elfogadva2/235ms4092 KiB
14Elfogadva2/235ms4216 KiB
15Elfogadva2/235ms4444 KiB
16Elfogadva2/235ms4364 KiB
17Elfogadva2/235ms4556 KiB
18Elfogadva2/235ms4680 KiB
19Elfogadva2/235ms4744 KiB
20Elfogadva2/235ms4872 KiB
21Elfogadva2/235ms4968 KiB
22Elfogadva2/235ms5096 KiB
23Elfogadva2/235ms5080 KiB
24Elfogadva2/235ms5172 KiB
25Elfogadva2/235ms5300 KiB
26Elfogadva2/235ms5476 KiB
27Elfogadva2/235ms5548 KiB