QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684219#9528. New Energy VehicleMCdycWA 0ms3792kbC++232.0kb2024-10-28 11:24:492024-10-28 11:24:49

Judging History

This is the latest submission verdict.

  • [2024-10-28 11:24:49]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3792kb
  • [2024-10-28 11:24:49]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    vector<queue<int>> cnt(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<pair<int, int>> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> b[i].first >> b[i].second;
    }
    b.emplace_back(0, 0);
    sort(all(b));
    for (int i = 1; i <= m; i++)
    {
        cnt[b[i].second].push(i);
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (int i = 1; i <= n; i++)
    {
        cnt[i].emplace(0x3f3f3f3f3f3f3f);
        q.emplace(cnt[i].front(), i);
        cnt[i].pop();
    }
    auto now = a;
    int res = 0;
    int tmp = 0;
    vector<int> pre(n + 1);
    for (int i = 1; i <= m; i++)
    {
        while (!q.empty() && res < b[i].first)
        {
            auto [x, y] = q.top();
            int p = min(b[i].first - res, now[y]);
            res += p;
            now[y] -= p;
            if (now[y] == 0)
            {
                q.pop();
            }
        }
        if (res < b[i].first)
        {
            while (!q.empty())
            {
                res += now[q.top().second];
                now[q.top().second] = 0;
                q.pop();
            }
            cout << res << "\n";
            return;
        }
        if (now[b[i].second] == 0)
        {
            q.emplace(cnt[b[i].second].front(), b[i].second);
            cnt[b[i].second].pop();
        }
        if (q.top().first == i)
        {
            q.pop();
            q.emplace(cnt[b[i].second].front(), b[i].second);
        }
        now[b[i].second] = a[b[i].second];
    }
    cout << res << "\n";
    return;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3792kb

input:

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

output:

8
2

result:

wrong answer 1st lines differ - expected: '12', found: '8'