QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698291#9528. New Energy VehicleRhyme3WA 1ms5696kbC++202.7kb2024-11-01 18:40:452024-11-01 18:40:45

Judging History

This is the latest submission verdict.

  • [2024-11-01 18:40:45]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5696kb
  • [2024-11-01 18:40:45]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#define For(i, a, n) for(int i = a; i <= n; i++)
#define inf 998244353
#define endl "\n"
using namespace std;
const int maxn = 1e5 + 5;
pair<ll, ll> a[maxn], b[maxn];
ll n, m, cnt, ans, x[maxn];
void work()
{
    cin >> n >> m;
    cnt = 1;
    ans = 0;
    vector<ll> num(n + 5), vis(n + 5);
    queue<ll> qq[n + 5];
    priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > q;
    For(i, 1, n)
    {
        cin >> a[i].first;
        a[i].second = a[i].first;
    }
    a[n + 1] = {0, 0};
    For(i, 1, m)
    {
        cin >> b[i].first >> b[i].second;
        x[i] = b[i].second;
        num[x[i]]++;
    }
    For(i, 1, n)
    {
        if(!num[i]) a[n + 1].second += a[i].second;
    }
    x[m + 1] = n + 1;
    For(i, 1, m)
    {
        bool ok = false;
        while(!q.empty())
        {
            auto [pre, res] = q.top();
            if(b[i].first - ans > a[res].second)
            {
                ans += a[res].second;
                a[res].second = 0;
                q.pop();
            }
            else{
                a[res].second -= b[i].first - ans;
                ans = b[i].first;
                ok = true;
                break;
            }
        }
        while(!ok && cnt <= m + 1 && ans < b[i].first)
        {
            while(cnt <= m + 1 && vis[x[cnt]]) 
            {
                qq[x[cnt]].push(cnt);
                vis[x[cnt]]++;
                cnt++;
            }
            if(cnt > m + 1) break;
            if(b[i].first - ans > a[x[cnt]].second)
            {
                ans += a[x[cnt]].second;
                a[x[cnt]].second = 0;
                vis[x[cnt]]++;
                cnt++;
            }
            else{
                a[x[cnt]].second -= b[i].first - ans;
                ans = b[i].first;
                ok = true;
                break;
            }
        }
        if(ok)
        {
            a[b[i].second].second = a[b[i].second].first;
            if(!q.empty() && b[i].second == q.top().second) q.pop();
            if(vis[b[i].second]) vis[b[i].second]--;
            if(vis[b[i].second])
            {
                q.push(make_pair(qq[b[i].second].front(), b[i].second));
                qq[b[i].second].pop();
            }
            num[b[i].second]--;
            if(!num[b[i].second]) a[n + 1].second += a[b[i].second].first;
        }
        else break;
    }
    if(a[n + 1].second)
    {
        ans += a[n + 1].second;
    }
    cout << ans << endl;
    return;
}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)
    {
        work();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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'