QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707156 | #9528. New Energy Vehicle | wjynb666 | WA | 0ms | 3744kb | C++14 | 1.6kb | 2024-11-03 14:54:26 | 2024-11-03 14:54:28 |
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;
struct cmp{
bool operator()(pair<int,int> a,pair<int,int> b){
if(a.first!=b.first)return a.first>b.first;
return a.second<b.second;
}
};
void solve(){
int n,m;
cin>>n>>m;
//先写一个O(n^2)的贪心
vector<int> a(n);
vector<int> s(a);
for(int i=0;i<n;i++) cin>>a[i],s[i]=a[i];
vector<array<int,2>> b(m);
priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
vector<int> st(n);
for(int i=0;i<m;i++) cin>>b[i][0]>>b[i][1],b[i][1]--,q.push({b[i][0],b[i][1]}),st[b[i][1]]=1;
sort(b.begin(),b.end());
for(int i=0;i<n;i++)
if(!st[i])
q.push({1e9+5,i});
ll ans=0;
int last=0;
for(int i=0;i<m;i++){
//依次去使用,后面的内容
int need=b[i][0]-last;
vector<pair<int,int>> tmp;
while(!q.empty()){
auto t=q.top();
q.pop();
tmp.push_back(t);
int res=min(need,a[t.second]);
a[t.second]-=res;
need-=res;
ans+=res;
if(need==0) break;
}
if(q.empty() && need>0) break;
for(auto x:tmp) q.push(x);
q.pop();
a[b[i][1]]=s[b[i][1]];
last=b[i][0];
}
for(int i=0;i<n;i++){
if(a[i]>0) ans+=a[i];
}
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: 3744kb
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: 3544kb
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'