QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685069 | #9528. New Energy Vehicle | OrangeQWQ | WA | 0ms | 3616kb | C++20 | 1.8kb | 2024-10-28 17:25:06 | 2024-10-28 17:25:07 |
Judging History
answer
// 16:30
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
#define int long long
// vector<pair<int, int>>
void solve() {
int n, m;
cin >> n >> m;
vector<int> p(n); // i 个电池的电量
vector<PII> sta(m); // first 距离 second ai
map<int, set<int>> ls; // 第 i 个站,可以冲哪个车车的电
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
cin >> sta[i].first >> sta[i].second;
ls[sta[i].first].insert(sta[i].second);
// cout << sta[i].first << ' ' << sta[i].second << endl;
}
sort(sta.begin(), sta.end());
vector<pair<int, set<int>>> omg(ls.begin(), ls.end());
sort(omg.begin(), omg.end(), [&](auto x, auto y) { return x.first < y.first; });
int now = accumulate(p.begin(), p.end(), 0ll); // 当前油量
int maxv = now;
int loc = 0; // 当前距离
for (auto v : omg) {
// cout << now << ' ' << loc << ' ' << v.first << endl;
if (now + loc >= v.first) {
now -= v.first - loc;
loc = v.first;
for (auto t : v.second) {
now += p[t - 1];
// cout << v.first << 'x' << t << ' ' << p[t - 1] << endl;
}
// cout << v.first << 'v' << now << endl;
now = min(maxv, max(now, 0ll));
}
// cout << v.first << ' ' << loc << ' ' << now << endl;
}
// cout << loc << ' ' << now << endl;
cout << loc + now << endl;
}
signed main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int T = 1;
cin >> T;
while (T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3616kb
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:
10 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'