QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685572 | #9528. New Energy Vehicle | PHarr | WA | 0ms | 3648kb | C++20 | 1.2kb | 2024-10-28 20:13:41 | 2024-10-28 20:13:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t;
using i64 = long long;
#define int i64
using vi = vector<int>;
using pii = pair<int,int>;
const int inf = LLONG_MAX / 2;
void solve() {
int n, m;
cin >> n >> m;
vi a(n + 1);
for(int i = 1; i <= n; i ++) cin >> a[i];
vi b = a;
vector<pii> charge(m);
for(auto &[x, t] : charge) cin >> x >> t;
vi lst(n + 1, inf), suf(m + 1);
for(int i = m - 1; i >= n; i --) {
auto [pos, ti] = charge[i];
suf[i] = lst[i], lst[ti] = i;
}
int now = 0;
priority_queue<pii, vector<pii>, greater<pii>> bank;
for(int i = 1; i <= n; i ++)
bank.emplace(lst[i], i);
for(int i = 0; i < m; i ++) {
auto[x, t] = charge[i];
while(now < x and not bank.empty()) {
auto [it, p] = bank.top();
bank.pop();
int y = min(x - now, b[p]);
now += y, b[p] -= y;
if(b[p] > 0 and p != t) bank.emplace(it, p);
}
if(now == x) {
b[t] = a[t];
bank.emplace(suf[i], t);
}else {
break;
}
}
for(auto i : b) {
now += i;
}
cout << now << "\n";
}
i32 main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T --)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3648kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
12 8
result:
wrong answer 2nd lines differ - expected: '9', found: '8'