QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#710269 | #9528. New Energy Vehicle | He_ng | WA | 0ms | 3816kb | C++20 | 2.2kb | 2024-11-04 19:15:20 | 2024-11-04 19:15:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i <= (y); ++i)
#define per(i, x, y) for (int i = (x); i >= (y); --i)
const int P = 998244353;
const int N = 1e6 + 10;
typedef long long ll;
#define int long long
void solve() {
int n, m;
cin >> n >> m;
vector<ll> a(n + 1);
vector<ll> val(n + 1);
rep(i, 1, n) {
cin >> a[i];
val[i] = a[i];
}
deque<ll> q;
vector<ll> x(m + 1), t(m + 1);
ll tot_trash = 0;
vector<bool> vis(n + 1);
vector<int> cnt(n + 1);
rep(i, 1, m) {
cin >> x[i] >> t[i];
q.push_back(t[i]);
cnt[t[i]]++;
vis[t[i]] = true;
}
rep(i, 1, n) if (!vis[i]) tot_trash += a[i];
vector<int> owe(n + 1);
rep(i, 1, m) {
ll need = x[i] - x[i - 1];
while (!q.empty()) {
int u = q.front();
q.pop_front();
if (a[u] == 0) {
owe[u]++;
continue;
} else {
if (a[u] <= need) {
need -= a[u], a[u] = 0;
} else {
a[u] -= need;
need = 0;
if (u != t[i])
q.push_front(u);
break;
}
}
}
if (need) {
if (need >= tot_trash) {
need -= tot_trash;
ll ans = x[i] - need;
cout << ans << '\n';
return;
} else {
tot_trash -= need;
}
}
if (owe[t[i]] > 0) {
q.push_front(t[i]);
owe[t[i]]--;
}
a[t[i]] = val[t[i]];
cnt[t[i]]--;
if (cnt[t[i]] == 0) {
tot_trash += a[t[i]];
a[t[i]] = 0;
}
}
ll ans = x[m] + tot_trash;
rep(i, 1, n) {
if (vis[i])
ans += a[i];
}
cout << ans << '\n';
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
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: 3548kb
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:
6 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'