QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#680086 | #9528. New Energy Vehicle | ucup-team3691# | WA | 122ms | 11736kb | C++14 | 2.8kb | 2024-10-26 19:45:50 | 2024-10-26 19:45:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
const ll INF = 1e18;
void solve() {
int n, m;
cin >> n >> m;
vector<ll> a(n + 1, 0);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vector<pair<ll, ll>> r(m + 1);
for (int i = 1; i <= m; ++i) {
cin >> r[i].first >> r[i].second;
}
set<int> b;
for (int i = 1; i <= n; ++i) {
b.insert(i);
r.push_back({INF, i});
}
vector<ll> rem = a;
ll last = 0;
int j = 1;
auto pick_battery = [&](ll dist) {
if (b.size() == 0)
return false;
int wb = -1;
while (j < r.size()) {
if (b.find(r[j].second) == b.end()) {
++j;
continue;
}
wb = r[j].second;
if (rem[wb] == 0) {
b.erase(wb);
wb = -1;
continue;
}
break;
}
while (wb == -1) {
if (b.empty())
return false;
wb = *b.begin();
if (rem[wb] == 0) {
b.erase(wb);
continue;
}
break;
}
ll t = min(dist, rem[wb]);
rem[wb] -= t;
last += t;
return true;
};
for (int i = 1; i <= m + 1; ++i) {
j = max(j, i);
while (last < r[i].first) {
if (!pick_battery(r[i].first - last)) {
break;
}
}
if (last < r[i].first)
break;
if (last == r[i].first) {
b.insert(r[i].second);
rem[r[i].second] = a[r[i].second];
}
}
cout << last << "\n";
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
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: 3624kb
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: 0
Accepted
time: 0ms
memory: 3620kb
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 11 4 11 999999999 2000000000
result:
ok 6 lines
Test #3:
score: -100
Wrong Answer
time: 122ms
memory: 11736kb
input:
10 230 8042 599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...
output:
1543020 1578939 1526016 1527381 1547404 1564631 1005900 1548178 1038745 1008772
result:
wrong answer 7th lines differ - expected: '1051729', found: '1005900'