QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#779540#9528. New Energy VehicleSunwkingWA 0ms3772kbC++201.8kb2024-11-24 19:42:432024-11-24 19:42:43

Judging History

This is the latest submission verdict.

  • [2024-11-24 19:42:43]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3772kb
  • [2024-11-24 19:42:43]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;
using LL = long long;

void solved() {

    int n , m;
    cin >> n >> m;

    vector<int> a(n + 1);
    for(int i = 1 ; i <= n ; i ++ )
        cin >> a[i];

    auto c = a;

    vector<array<LL ,2>> b(m + 1);
    for(int i = 1 ; i <= m ; i ++ )
        for(int j = 0 ; j < 2 ; j ++ )
            cin >> b[i][j];
    map<int , int> mp;
    vector<int> nxt(m + 1 , m + 1);
    for(int i = m ; i ; i -- ){
        auto [x , t] = b[i];
        if(mp[t]){
            nxt[i] = mp[t];
        }
        mp[t] = i;
    }

    LL sum = 0;
    priority_queue<array<LL , 2> , vector<array<LL , 2>> , greater<array<LL , 2>>> q;
    for(int i = 1 ; i <= m ; i ++ )
        if(mp[b[i][1]] == i){
            q.push({i , b[i][1]});
        }
    for(int i = 1 ; i <= n ; i ++ )
        if(!mp[i]) sum += a[i];

    LL ans = 0;
    for(int i = 1 ; i <= m ; i ++ ){
        LL s = b[i][0] - b[i - 1][0];

        while(s && !q.empty()){
            auto [x , j] = q.top();
            q.pop();

            if(s >= a[j]) s -= a[j] , a[j] = 0;
            else {
                s = 0;
                a[j] -= s;
                if(j != b[i][1]) q.push({x , j});
            }
        }

        if(s > sum){
            cout << b[i][0] - s << "\n";
            return ;
        }
        sum -= s;
        q.push({nxt[i] , b[i][1]});
        a[b[i][1]] = c[b[i][1]];
    }

    ans = b[m][0] + sum;
    while(!q.empty()){
        auto [x , y]  = q.top();
        q.pop();

        ans += a[y];
    }

    cout << ans << "\n";
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;

    while(t -- )
        solved();

    return 0;
}

详细

Test #1:

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

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

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'