QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#681858#9528. New Energy Vehicleqianchen06WA 1ms3624kbC++141.8kb2024-10-27 12:28:572024-10-27 12:28:59

Judging History

This is the latest submission verdict.

  • [2024-10-27 12:28:59]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3624kb
  • [2024-10-27 12:28:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int n, m;
const int inf = 1e9 + 10;
const int maxn = 1e5 + 10;
int a[maxn];
vector<queue<int>> vec;
int x[maxn];
int vis[maxn];
int t[maxn];
void solve()
{
    cin >> n >> m;
    vec.resize(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> x[i] >> t[i];
        vec[t[i]].push(x[i]);
    }

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (int i = 1; i <= n; i++)
    {
        if (vec[i].size())
        {
            q.push({vec[i].front(), a[i]});
            vec[i].pop();
        }
        else
        {
            q.push({inf, a[i]});
            // vis[i] = 1;
        }
    }
    int j = 1;
    int ans = 0;
    while (q.size() && j <= m)
    {
        auto ft = q.top();
        q.pop();
        if (ans + ft.second >= x[j])
        {
            ft.second -= x[j] - ans;
            ans = x[j];
            if (ft.second && ft.first != x[j])
            {
                q.push(ft);
            }
            if (vec[t[j]].size())
            {
                q.push({vec[t[j]].front(), a[t[j]]});
                vec[t[j]].pop();
            }
            else
            {
                q.push({inf, a[t[j]]});
                // vis[t[j]] = 1;
            }
            j++;
        }
        else
        {
            ans += ft.second;
        }
    }

    while (q.size())
    {
        auto ft = q.top();
        q.pop();
        ans += ft.second;
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    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: 3624kb

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: 3596kb

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
11
4
12
999999999
2000000000

result:

wrong answer 4th lines differ - expected: '11', found: '12'