QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682695 | #9528. New Energy Vehicle | SCAU_xyjkanade# | WA | 0ms | 19944kb | C++17 | 2.0kb | 2024-10-27 16:59:41 | 2024-10-27 16:59:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
typedef long long ll;
struct node{
ll pos;
int id,f;
bool operator<(const node & a) const {
return pos > a.pos;//重载,从小到大排序
}
}b[N];
int n,m;
int x[N],t[N];
ll a[N],ora[N];
vector<int>e[N];
int num[N];
int now[N];
void solve(){
priority_queue<node>q;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
ora[i] = a[i];
e[i].clear();
num[i] = 0;
}
for(int i = 1; i <= m; i++){
cin >> x[i] >> t[i];
e[t[i]].push_back(x[i]);
now[i] = num[t[i]];
num[t[i]]++;
}
ll sum = 0;
for(int i = 1; i <= n; i++){
if(num[i] == 0){
sum += a[i];
a[i] = 0;
continue;
}
q.push({e[i][0],i,0});
}
ll ans = 0;
for(int i = 1; i <= m; i++){
int id = t[i];
int pos = x[i];
while(!q.empty()){
auto tx = q.top();
q.pop();
int j = tx.id;
if(tx.f + 1 < num[j])
q.push({e[j][tx.f + 1],j,tx.f + 1});
if(a[j] >= pos - ans){
a[j] -= (pos - ans);
ans = pos;
break;
}
else{
ans += a[j];
a[j] = 0;
}
}
if(pos == ans){
a[id] = ora[id];
if(now[i] + 1 >= num[id]){
sum += a[id];
a[id] = 0;
}
}
else if(pos <= ans + sum){
sum -= (pos - ans);
a[id] = ora[id];
ans = pos;
}
else{
break;
}
}
for(int i = 1; i <= n; i++){
ans += (ll)a[i];
}
ans += sum;
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T = 1;
cin >> T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 19944kb
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: 19880kb
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 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '8'