QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702223 | #9528. New Energy Vehicle | sw7777# | WA | 1ms | 10020kb | C++20 | 2.3kb | 2024-11-02 15:31:13 | 2024-11-02 15:31:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5+10;
struct chong{
int dis;
int x;
bool operator < (const chong &b) const{
return dis > b.dis;
}
}chg[maxn];
int a[maxn],ma[maxn];
vector <int> e[maxn];
int cnt[maxn];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int only = 0;
for(int i = 1;i<=n;i++) cnt[i] = 0,e[i].clear();//
for(int i = 1;i<=n;i++){
cin>>a[i];
ma[i] = a[i];
only += a[i];
}
map<int,int> mp;
for(int i = 1;i<=m;i++){
cin>>chg[i].dis>>chg[i].x;
e[chg[i].x].push_back(chg[i].dis);
if(!mp[chg[i].x]){
only -= a[chg[i].x];
mp[chg[i].x] = 1;
}
}
chg[m+1] = {(int)1e18,0};
for(int i = 1;i<=m;i++) e[i].push_back((int)1e18);
priority_queue<chong> q;
for(int i = 1;i<=n;i++){
if(mp[i]){
q.push({e[i][0],i});
}
}
int di = 0;
int nxc = 1;
while(!q.empty()||only){
if(q.empty()){
if(only + di < chg[nxc].dis){
di += only;
only = 0;
}
else{
only -= (chg[nxc].dis - di);
di = chg[nxc].dis;
a[chg[nxc].x] = ma[chg[nxc].x];
cnt[chg[nxc].x] ++;
q.push({e[chg[nxc].x][cnt[chg[nxc].x]],chg[nxc].x});
nxc ++ ;
}
}
else{
int x = q.top().x;
q.pop();
if(a[x] + di < chg[nxc].dis){
di += a[x];
a[x] = 0;
}
else{
a[x] -= (chg[nxc].dis - di);
di = chg[nxc].dis;
a[chg[nxc].x] = ma[chg[nxc].x];
cnt[chg[nxc].x] ++;
q.push({e[chg[nxc].x][cnt[chg[nxc].x]],chg[nxc].x});
nxc ++ ;
}
}
}
cout<<di<<endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7948kb
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: 1ms
memory: 10020kb
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 9 4 9 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '9'