QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712770 | #9528. New Energy Vehicle | podys | WA | 7ms | 73432kb | C++14 | 1.8kb | 2024-11-05 17:00:15 | 2024-11-05 17:00:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
struct stu{
int x,t;
bool operator<(const stu &b)const{
return x<b.x;
}
bool operator>(const stu &b)const{
return x>b.x;
}
};
int a[100005],sum[100005];
stu b[100005];
queue<int> mp[100005];
void solve(){
int n,m;
cin>>n>>m;
priority_queue<stu,vector<stu>,greater<stu>> que;
for(int i=1;i<=n;i++){
cin>>a[i];
sum[i]=a[i];
mp[i]=queue<int>();
}
for(int i=1;i<=m;i++){
cin>>b[i].x>>b[i].t;
if(mp[b[i].t].empty()) que.push(b[i]);
mp[b[i].t].push(b[i].t);
}
for(int i=1;i<=n;i++){
if(!mp[i].size()){
que.push({INT64_MAX,i});
}
}
b[0]={0,0};
for(int i=1;i<=m;i++){
int x=b[i].x;
int now=b[i].x-b[i-1].x;
while(!que.empty() && now){
int t=que.top().t;
if(sum[t]>now){
sum[t]-=now;
now=0;
}else{
now-=sum[t];
sum[t]=0;
que.pop();
}
}
if(now){
cout<<b[i].x-now<<endl;
return;
}
int t=b[i].t;
sum[t]=a[t];
mp[t].pop();
if(mp[t].size()==0){
que.push({INT64_MAX,t});
}else{
que.push({mp[t].front(),t});
}
while(!que.empty() && que.top().x<=x){
que.pop();
}
}
int now=0;
while(!que.empty()){
int t=que.top().t;
now+=sum[t];
que.pop();
}
cout<<b[m].x+now<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 72832kb
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: 73432kb
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:
6 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'