QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687222 | #9528. New Energy Vehicle | galiyuu | WA | 1ms | 7668kb | C++14 | 1.4kb | 2024-10-29 17:40:35 | 2024-10-29 17:40:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n'
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double db;
mt19937 mrand(random_device{}());
int rnd(int x) {return mrand()%x;}
const ll mod=998244353;
// head
const int N=2e5+10;
ll n,m;
ll a[N],ca[N],x[N],t[N];
void solve() {
cin>>n>>m;
rep(i,1,n+1) {
cin>>a[i];
ca[i]=a[i];
}
rep(i,1,m+1) cin>>x[i]>>t[i];
vl nxt(m+1,m+1),pos(n+1,m+1);
per(i,1,m+1) {
nxt[i]=pos[t[i]];
pos[t[i]]=i;
}
priority_queue<pll> q;
rep(i,1,n+1) q.push(mp(-pos[i],i));
ll nw=0;
rep(i,1,m+1) {
bool ch=0;
while (SZ(q)&&nw<x[i]) {
auto u=q.top();
q.pop();
ll c=min(x[i]-nw,a[u.se]);
nw+=c,a[u.se]-=c;
if (a[u.se]>0) {
if (u.se==t[i]) {
q.push(mp(-nxt[i],u.se));
a[u.se]=ca[u.se];
ch=1;
} else {
q.push(u);
}
}
}
if (!ch) {
q.push(mp(-nxt[i],t[i]));
a[t[i]]=ca[t[i]];
}
}
rep(i,1,n+1) nw+=a[i];
cout<<nw<<endl;
}
int tc;
signed main() {
ios::sync_with_stdio(0);
cin>>tc;
while (tc--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7668kb
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: 7656kb
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 11 10 11 1999999998 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '10'