QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750931#9528. New Energy VehicleTmonkeyWA 1ms5652kbC++201.9kb2024-11-15 16:24:422024-11-15 16:24:43

Judging History

This is the latest submission verdict.

  • [2024-11-15 16:24:43]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5652kb
  • [2024-11-15 16:24:42]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5;
int T = 1;
int n, m;
ll a[N + 5], b[N + 5];
ll now[N + 5], pos[N + 5];
vector<int> g[N + 5];
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        now[i] = a[i];
        g[i].clear();
    }
    priority_queue<pii, vector<pii>, greater<pii>> q;
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i] >> pos[i];
        g[pos[i]].push_back(i);
        q.push({i, pos[i]});
    }
    ll sum = 0, cur = 0;
    for (int i = 1; i <= n; i++)
    {
        if (g[i].empty())
        {
            sum += a[i];
            now[i] = 0;
        }
    }
    for (int i = 1; i <= m; i++)
    {
        while (!q.empty() && cur < b[i])
        {
            int p = q.top().second;
            int num = q.top().first;
            // cout << p << '\n';
            q.pop();
            if (now[p] < b[i] - cur)
            {
                cur += now[p];
                now[p] = 0;
            }
            else
            {
                now[p] -= b[i] - cur;
                cur += b[i] - cur;
                if (now[p] > 0)
                    q.push({num, p});
            }
        }
        if (sum < b[i] - cur)
            break;
        sum -= b[i] - cur;
        cur += b[i] - cur;

        auto it = upper_bound(g[pos[i]].begin(), g[pos[i]].end(), i);

        if (it == g[pos[i]].end())
            sum += a[pos[i]];
        else
        {
            if (q.empty() || (*it) < q.top().first)
                q.push({(*it), pos[i]});
            now[pos[i]] = a[pos[i]];
            // cout << "YES\n";
        }
        // cout << cur << '\n';
    }
    cout << cur + sum << '\n';
}
int main()
{
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5652kb

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: 1ms
memory: 5600kb

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:

9
12
4
12
999999999
2000000000

result:

wrong answer 2nd lines differ - expected: '11', found: '12'