QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696690#9528. New Energy VehiclepanelopeWA 103ms12504kbC++171.8kb2024-11-01 00:29:162024-11-01 00:29:17

Judging History

This is the latest submission verdict.

  • [2024-11-01 00:29:17]
  • Judged
  • Verdict: WA
  • Time: 103ms
  • Memory: 12504kb
  • [2024-11-01 00:29:16]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

int n,m;
struct ty{
    long long x,t,cur;
    int i;
    bool operator < (const ty &b) const{
        return t > b.t;
    }
};
ty a[100010];
long long x[100010],t[100010];
priority_queue<ty> q;
int main(){
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        long long ans = 0;
        for(int i=1; i<=n; i++)
        {    
            cin >> a[i].x;
            a[i].cur = a[i].x;
            a[i].i = i;
            ans += a[i].x;
        }
        for(int i=1; i<=m; i++)
        {
            cin >> x[i] >> t[i];
            a[t[i]].t = x[i];
            q.push(a[t[i]]);
        }
        //cout << q.size() << endl;
        for(int i=1; i<=n; i++)
        {
            if(a[i].t == 0)
            {
                a[i].t = 1e9+1;
                q.push(a[i]);
            }
        }
        //cout << q.top().i << endl;
        for(int i=1; i<=m; i++){
            long long p = 0;
            while(p < x[i]-x[i-1] && !q.empty()){
                ty cur = q.top();
                q.pop();
                long long l = x[i]-x[i-1] - p;
                //cout << l << ' ' << cur.i << endl;
                if(a[cur.i].cur>=l){
                    a[cur.i].cur -= l;
                    p += l;    
                }
                else{
                    p += a[cur.i].cur;
                    a[cur.i].cur = 0;
                }
                //cout << cur.i <<' ' <<a[cur.i].cur << endl;
            }
            if(p!=x[i]-x[i-1])break;
            //cout << a[t[i]].x << ' ' << a[t[i]].cur<<endl;
            ans += a[t[i]].x - a[t[i]].cur;
            a[t[i]].cur = a[t[i]].x;
            a[t[i]].t = 1e9+1;
            q.push(a[t[i]]);
        }
        while(q.size())q.pop();
        cout << ans << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3584kb

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

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 103ms
memory: 12504kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1514926
1565025
1315815
1516702
1513353
1554144
644255
1538191
789057
663453

result:

wrong answer 1st lines differ - expected: '1543020', found: '1514926'