QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716779 | #9528. New Energy Vehicle | obiwan114 | RE | 0ms | 3540kb | C++20 | 1.3kb | 2024-11-06 16:01:42 | 2024-11-06 16:01:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define int long long
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MAXX = 2e5 + 10;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
void solve() {
int n,m;
cin >> n >> m;
vector<ll>a(n + 5);
vector<ll>b(n + 5);
vector<ll>x(m + 5);
vector<ll>t(m + 5);
vector<ll>nx(m + 5);
vector<int>h(n + 5,m + 1);
for(int i = 1;i <= n;i++){
cin >> a[i];
b[i] = a[i];
}
for(int i = 1;i <= m;i++){
cin >> x[i] >> t[i];
}
// x[m + 1] = INF;
for(int i = m;i >= 1;i--){
nx[i] = h[x[i]];
h[x[i]] = i;
}
priority_queue<pll,vector<pll>,greater<>>q;
for(int i = 1;i <= n;i++){
q.push({h[i],i});
}
int l = 1;
ll ans = 0;
while(!q.empty()){
auto [w,u] = q.top();
if(x[l] - ans > b[u]){
ans += b[u];
b[u] = 0;
q.pop();
}else{
b[u] -= x[l] - ans;
ans = x[l];
if(t[l] == u || b[u] == 0)q.pop();
b[t[l]] = a[t[l]];
q.push({nx[t[l]],t[l]});
l++;
}
}
cout << ans << "\n";
}
signed main() {
int t = 1;
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: 3540kb
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
Runtime Error
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 9 4 9