QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730164 | #9528. New Energy Vehicle | DBsoleil# | WA | 11ms | 70876kb | C++23 | 1.5kb | 2024-11-09 18:57:34 | 2024-11-09 18:57:35 |
Judging History
answer
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
int n,m,a[N],T;
struct z{
int x,w;
bool operator <(const z&_)const{
return x>_.x;
}
};
const int INF=1e9+1;
queue<z>sta;
priority_queue<z>q;
queue<int>t[N];
int main(){
cin>>T;
while(T--){
scanf("%d%d",&n,&m);
while(!sta.empty())sta.pop();
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=m;i++){
int x,w;
scanf("%d%d",&x,&w);
t[w].push(x);
sta.push((z){x,w});
}
for(int i=1;i<=n;i++){
if(t[i].empty())q.push((z){INF,a[i]});
else q.push((z){t[i].front(),a[i]});
}
ll now=0;
while(!q.empty()){
if(sta.empty()){
now+=q.top().w;
q.pop();continue;
}
if(now+q.top().w<sta.front().x){
now+=q.top().w;
q.pop();
}else{
ll tmp=q.top().w-(sta.front().x-now),tx=q.top().x;
now=sta.front().x;
q.pop();
q.push((z){tx,tmp});
if(q.top().x==sta.front().x)q.pop();
ll tw=sta.front().w;
sta.pop();
t[tw].pop();
if(t[tw].empty())q.push((z){INF,a[tw]});
else q.push((z){t[tw].front(),a[tw]});
}
}
cout<<now<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 70876kb
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: 7ms
memory: 70848kb
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'