QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685868 | #9528. New Energy Vehicle | megumi# | RE | 4ms | 74596kb | C++17 | 1.9kb | 2024-10-28 21:42:37 | 2024-10-28 21:42:38 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e9, mod = 1e9 + 7;
typedef long long ll;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
f = (c == '-') ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
struct node {
int r, v;
bool operator<(const node &a) const { return r > a.r; }
};
priority_queue<node> q;
int a[100010];
vector<int> b[100010];
queue<int> p[100010];
int c[100010];
int d[100010];
void solve() {
int n = read(), m = read();
for (int i = 1; i <= n; i++)
a[i] = read(), b[i].clear();
for (int i = 1; i <= m; i++) {
int x = read(), t = read();
c[i] = x, d[i] = t;
b[t].push_back(x);
}
for (int i = 1; i <= n; i++) {
sort(b[i].begin(), b[i].end());
while (!p[i].empty())
p[i].pop();
for (int j = 0; j < b[i].size(); j++)
p[i].push(b[i][j]);
p[i].push(5e17);
q.push({p[i].front(), a[i]});
p[i].pop();
}
c[0] = 0;
c[m + 1] = 5e17 - 1;
for (int i = 1; i <= m + 1; i++) {
int len = c[i] - c[i - 1];
while (!q.empty()) {
if (q.top().v >= len) {
node z = {q.top().r, q.top().v - len};
len = 0;
q.pop();
if (z.v != 0)
q.push(z);
break;
} else {
len -= q.top().v;
q.pop();
}
}
if (len) {
cout << c[i] - len << "\n";
return;
}
if (q.top().r == c[i])
q.pop();
q.push({p[d[i]].front(), a[d[i]]});
p[d[i]].pop();
}
}
signed main() {
int T = read();
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 74596kb
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
Runtime Error
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