QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690181#9528. New Energy Vehicle0x3eaWA 0ms3556kbC++172.3kb2024-10-30 20:44:482024-10-30 20:44:49

Judging History

This is the latest submission verdict.

  • [2024-10-30 20:44:49]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3556kb
  • [2024-10-30 20:44:48]
  • Submitted

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 2e5 + 100;
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n + 1), now(n + 1);
    vector<int> x(m + 1), t(m + 1);
    vector<int> mx(n + 1, 0);
    for (int i = 1; i <= n; i++)
        cin >> a[i], now[i] = a[i];
    multiset<pii> s;
    set<int> fr;

    for (int i = 1; i <= m; i++)
    {
        cin >> x[i] >> t[i];
        s.insert({i, t[i]});
        mx[t[i]] = max(mx[t[i]], i);
    }
    for (int i = 1; i <= n; i++)
        if (!mx[i])
            fr.insert(i);

    // cout << "s" << endl;
    // for (auto &[pos, u] : s)
    //     cout << pos << " " << u << endl;
    // cout << endl;
    // cout << "fr" << endl;
    // for (auto u : fr)
    //     cout << u << endl;
    // cout << endl;
    // return;
    auto upd = [&](multiset<pii> &s, ll &ne) -> void
    {
        vector<int> del;
        for (auto &[pos, u] : s)
        {
            ll sub = min(ne, now[u]);
            ne -= sub, now[u] -= sub;
            if (!now[u])
                del.push_back(pos);
        }
        for (auto &j : del)
            s.extract({j, t[j]});
    };
    int lst = 0;
    for (int i = 1; i <= m; i++)
    {
        ll ne = x[i] - lst;
        upd(s, ne);
        vector<int> del;
        for (auto &j : fr)
        {
            ll sub = min(ne, now[j]);
            ne -= sub, now[j] -= sub;
            if (!now[j])
                del.push_back(j);
        }
        for (auto &j : del)
            fr.erase(j);
        if (ne)
        {
            cout << x[i] - ne << endl;
            return;
        }
        lst = x[i];
        now[t[i]] = a[t[i]];
        auto it = s.lower_bound({i, t[i]});
        if (it != s.end() && (*it).second == t[i])
            s.extract({i, t[i]});
        if (mx[t[i]] == i)
            fr.insert({i, t[i]});
    }

    ll ans = x[m];
    for (int i = 1; i <= n; i++)
        ans += now[i];
    cout << ans << endl;
}
int main()
{
#ifdef x3ea
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    for (; _; _--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3548kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

6
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '6'