QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#754635 | #9521. Giving Directions in Harbin | ANIG# | WA | 2ms | 12204kb | C++14 | 1.3kb | 2024-11-16 15:27:30 | 2024-11-16 15:27:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int t,n,m,w[N],g[N],wz[N],p[N];
struct node{
int bh,wz;
friend bool operator<(node a,node b){
return a.wz<b.wz;
}
};
priority_queue<node>q;
vector<int>gs[N];
signed main(){
cin>>t;
while(t--){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>w[i],g[i]=w[i],gs[i].clear();
for(int i=1;i<=m;i++)cin>>wz[i]>>p[i],gs[p[i]].push_back(i);
for(int i=1;i<=n;i++)gs[i].push_back(m+1);
for(int i=1;i<=n;i++){
q.push({i,gs[i][0]});
}
int res=0;
for(int i=1;i<=m;i++){
int nw=wz[i]-wz[i-1];
while(q.size()&&g[q.top().bh]<=nw){
int x=q.top().bh;
nw-=g[x];
res+=g[x];
g[x]=0;
q.pop();
}
if(q.size()){
int x=q.top().bh;
g[x]-=nw;
res+=nw;
nw=0;
}
if(nw)break;
if(q.size()&&q.top().bh==p[i])q.pop();
g[p[i]]=w[p[i]];
q.push({p[i],*upper_bound(gs[p[i]].begin(),gs[p[i]].end(),i)});
}
for(int i=1;i<=n;i++)res+=g[i];
cout<<res<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12204kb
input:
1 2 S 2 E 1
output:
0
result:
wrong answer Integer parameter [name=m] equals to 0, violates the range [1, 20] (test case 1)