QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#722593 | #9528. New Energy Vehicle | yyk | WA | 0ms | 3616kb | C++14 | 1.3kb | 2024-11-07 19:37:51 | 2024-11-07 19:37:54 |
Judging History
answer
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=100010;
int n,m;
int a[N],c[N];
PII b[N];
int main() {
int T;
cin>>T;
while(T--){
cin>>n>>m;
queue<int> h[n+10];
priority_queue<PII,vector<PII>,greater<PII>> pq;
for(int i=1;i<=n;++i){
cin>>a[i];
}
for(int i=1;i<=m;++i){
cin>>b[i].x>>b[i].y;
h[b[i].y].push(i);
}
for(int i=1;i<=n;++i){
if(h[i].size()){
int t=h[i].front();
h[i].pop();
pq.push({t,a[i]});
}
else{
pq.push({1e9,a[i]});
}
}
LL now=0;
for(int i=1;i<=m;++i){
while(pq.size()&&pq.top().x<i) pq.pop();
while(pq.size()&&now<b[i].x){
PII t=pq.top();
pq.pop();
int tmp=min(b[i].x-now,(LL)t.y);
now+=tmp;
t.y-=tmp;
if(t.y){
pq.push(t);
}
}
if(now==b[i].x){
if(h[b[i].y].size()){
int t=h[b[i].y].front();
h[b[i].y].pop();
pq.push({t,a[b[i].y]});
}
else{
pq.push({1e9,a[b[i].y]});
}
}
}
while(pq.size()&&pq.top().x<=n) pq.pop();
while(pq.size()){
PII t=pq.top();
cout<<t.y<<endl;
pq.pop();
now+=t.y;
}
cout<<now<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
1 3 12 2 5 9
result:
wrong answer 1st lines differ - expected: '12', found: '1'