QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689321 | #9528. New Energy Vehicle | yingling# | WA | 1ms | 3672kb | C++20 | 1.7kb | 2024-10-30 16:22:57 | 2024-10-30 16:22:57 |
Judging History
answer
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
typedef pair<int, int> PII;
void solve()
{
int n, m;
cin >> n >> m;
vector<int> a(n + 7);
vector<PII> pd;
vector<int> cnt(n + 7);
for (int i = 1; i <= n; i++)
cin >> a[i];
auto b = a;
for (int i = 1; i <= m; i++) {
int x, t;
cin >> x >> t;
pd.push_back({x, t});
cnt[t] ++;
}
int now = 0, idx = 0, sum = 0;
for (int i = 1; i <= n ; i ++) {
if (!cnt[i])
sum += a[i];
}
int idxr = 0;
while (idx < m) {
while (1) {
if (idxr < m) {
if (now + a[pd[idxr].second] < pd[idx].first)
now += a[pd[idxr].second], a[pd[idxr].second] = 0;
else {
a[pd[idxr].second] -= pd[idx].first - now;
now = pd[idx].first;
break;
}
}
else {
if (now + sum < pd[idx].first) {
now += sum;
cout << now << endl;
return;
}
else {
sum -= pd[idx].first - now;
now = pd[idx].first;
break;
}
}
idxr ++;
}
a[pd[idx].second] = b[pd[idx].second];
cnt[pd[idx].second] --;
if (!cnt[pd[idx].second])
sum += a[pd[idx].second];
idx ++;
}
cout << now + sum << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
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: 1ms
memory: 3672kb
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: 3556kb
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 12 4 12 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'