30632023-02-11 14:11:021478Ládapakolás raktárban (50)cpp17Wrong answer 17/5032ms8000 KiB
#include <bits/stdc++.h>
#include <random>

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 fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

set<int> s;
int a;
int latest;
int w;
bool isLegal()
{
    if (s.find(a) == s.end())
    {
        if (a < latest)
        {
            return true;
        }
        else if (!s.empty() && latest == *prev(s.end(), 1))
        {
            return true;
        }
    }

    return false;
}

int main()
{
    fast_cin();
    //ifstream cin("in.txt");

    int n;
    cin >> n;
    int m;
    cin >> m;

    int ans = 0;

    cin >> latest;
    s.insert(latest);

    w = latest;

    for (int i = 2; i <= n; i++)
    {
        cin >> a;

        if (isLegal() && w + a <= m)
        {
            s.insert(a);
            w += a;
        }
        else
        {
            ans += s.size() - 1;
            s.clear();
            s.insert(a);
            w = a;
        }
        latest = a;
    }
    cout << ans;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base17/50
1Accepted0/03ms1764 KiB
2Wrong answer0/04ms2092 KiB
3Wrong answer0/23ms2028 KiB
4Wrong answer0/23ms2228 KiB
5Accepted2/23ms2432 KiB
6Wrong answer0/23ms2648 KiB
7Accepted2/23ms3116 KiB
8Wrong answer0/23ms3016 KiB
9Wrong answer0/33ms2968 KiB
10Wrong answer0/23ms3108 KiB
11Accepted2/23ms3320 KiB
12Wrong answer0/23ms3336 KiB
13Wrong answer0/33ms3460 KiB
14Accepted3/34ms3540 KiB
15Wrong answer0/34ms3648 KiB
16Accepted2/217ms3608 KiB
17Accepted3/318ms3956 KiB
18Accepted3/320ms4080 KiB
19Wrong answer0/319ms4456 KiB
20Wrong answer0/332ms7496 KiB
21Wrong answer0/328ms7488 KiB
22Wrong answer0/327ms8000 KiB