QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686290 | #9528. New Energy Vehicle | blhxzjr | WA | 2ms | 7936kb | C++23 | 1.5kb | 2024-10-29 10:36:01 | 2024-10-29 10:36:01 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
using PII = pair<int,int>;
const int N=1e6+10;
int n,m,_;
int a[N],b[N];
//a为当前 b是容量
vector<int>g[N];
//存每种油的加油时刻点
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++) {
cin>>a[i];
b[i]=a[i];
g[i].clear();
}
vector<pair<int,int>>p;
for(int i=1;i<=m;i++){
int id,d;
cin>>d>>id;
g[id].push_back(d);
p.push_back({d,id});
}
multiset<pair<int,int>>st;
for(int i=1;i<=n;i++){
if(g[i].size()){
// st.insert({g[i][0],i});
// reverse(g[i].begin(),g[i].end());
// g[i].pop_back();
for(auto j:g[i]){
st.insert({j,i});
}
st.insert({1e9+2ll,i});
}
else
st.insert({1e9+1ll,i});
}
int j=0;//存当前走到哪个加油站
int sum=0;
while(st.size()){
pair<int,int> temp=*st.begin();
int id=temp.second;
sum+=a[id];
a[id]=0;
st.erase(st.find(temp));
//加油
while((j<m&&p[j].first<=sum)){
int ii=p[j].second;
a[ii]=b[ii];
if(st.find({p[j].first,ii})!=st.end())
st.erase(st.find({p[j].first,ii}));
// if(g[ii].size()){
// st.insert({g[ii].back(),ii});
// g[ii].pop_back();
// }
j++;
}
//检查后面还有没有加油站
// if(g[id].size()){
// st.insert({g[id].back(),id});
// g[id].pop_back();
// }
}
cout<<sum<<endl;
}
signed main(){
ios_base::sync_with_stdio(false),cin.tie(0);
_=1;
cin >> _;
while(_--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7712kb
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: 2ms
memory: 7936kb
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:
8 12 4 12 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '8'