QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708230 | #9528. New Energy Vehicle | wjynb666 | WA | 0ms | 3612kb | C++14 | 1.8kb | 2024-11-03 20:36:58 | 2024-11-03 20:36:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define read_fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using ll=long long;
using PII=pair<int,int>;
void solve(){
int n,m;
cin>>n>>m;
//先写一个O(n^2)的贪心
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
vector<int> sq(a);
vector<array<int,2>> b(m);
for(int i=0;i<m;i++) cin>>b[i][0]>>b[i][1],b[i][1]--;
sort(b.begin(),b.end());
queue<int> nxt[n+1];
for(int i=0;i<m;i++){
nxt[b[i][1]].push(b[i][0]);
}
priority_queue<PII,vector<PII>,greater<PII>> q;//s中只维护邮箱里有油的的邮箱
for(int i=0;i<n;i++){
if(nxt[i].empty()) q.push({1e9+5,i});
else q.push({nxt[i].front(),i});
}
ll ans=0;
int last=0;
for(int i=0;i<m;i++){
//依次去使用,后面的内容
int need=b[i][0]-last;
while(!q.empty()){
auto t=q.top();
q.pop();
int res=min(need,a[t.second]);
a[t.second]-=res;
need-=res;
ans+=res;
if(a[t.second] && t.second!=b[i][1]) q.push({a[t.second],t.second});
if(need==0) break;
}
//cerr<<"need="<<need<<"\n";
if(need>0) break;
a[b[i][1]]=sq[b[i][1]];
//第b[i][1]有油了,加上去,那它的位置是哪个呢?
if(!nxt[b[i][1]].empty()) nxt[b[i][1]].pop();
if(!nxt[b[i][1]].empty()) q.push({nxt[b[i][1]].front(),b[i][1]});
last=b[i][0];
}
for(int i=0;i<n;i++){
if(a[i]>0) {
//cerr<<a[i]<<' ';
ans+=a[i];
}
}
//cerr<<"\n-------\n";
cout<<ans<<'\n';
}
int main()
{
read_fast;
int t;
cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 0ms
memory: 3588kb
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 8 4 8 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '8'