QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691161 | #9528. New Energy Vehicle | For_rest | WA | 15ms | 71312kb | C++14 | 1.6kb | 2024-10-31 10:11:07 | 2024-10-31 10:11:07 |
Judging History
answer
/*
Tips:
1.Remember to consider the zero situation in the covering problems
2.Remember to test the special small samples
3.Binary search : which side of the interval is closed
*/
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = a; i <= ll(b); ++i)
#define REP(a) for(ll i = 0;i < a;i++)
#define REM(a,b) (((a)%(b) == 0)?(b):((a)%(b)+(b))%(b))
typedef long long ll;
typedef double db;
typedef array<ll,2> pr;
constexpr ll NAX = 1e5+10;
constexpr ll M = 0;
constexpr ll PINF = 0x3FFFFFFFFFFFFFFF;
constexpr ll NINF = -0x3FFFFFFFFFFFFFFF;
ll alst[NAX],xlst[NAX],tlst[NAX];
queue<ll> que[NAX];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t,n,m;
cin >> t;
while(t--){
cin >> n >> m;
FOR(i,1,n){
cin >> alst[i];
}
FOR(i,1,m){
cin >> xlst[i] >> tlst[i];
que[tlst[i]].push(xlst[i]);
}
FOR(i,1,n){
que[i].push(PINF);
}
ll nxt = 1,cur = 0;
priority_queue<pr,vector<pr>,greater<pr>> rem;
FOR(i,1,n){
ll p = que[i].front();
que[i].pop();
rem.push({p,alst[i]});
}
xlst[m+1] = PINF+1;
while(!rem.empty()){
pr p = rem.top();
rem.pop();
if(cur+p[1] < xlst[nxt]){
cur += p[1];
}
else{
ll q = que[tlst[nxt]].front();
que[tlst[nxt]].pop();
if(p[0] == xlst[nxt]){
p[1] = alst[tlst[nxt]];
p[0] = q;
rem.push(p);
}
else{
p[1] -= xlst[nxt]-cur;
if(p[1] > 0)rem.push(p);
rem.push({q,alst[tlst[nxt]]});
}
cur = xlst[nxt];
nxt++;
}
}
cout << cur << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 71244kb
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: 8ms
memory: 71312kb
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'