QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685806 | #9528. New Energy Vehicle | megumi# | WA | 11ms | 74404kb | C++17 | 1.8kb | 2024-10-28 21:24:16 | 2024-10-28 21:24:17 |
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());
for (int j = 0; j < b[i].size(); j++)
p[i].push(b[i][j]);
p[i].push(1e14);
q.push({p[i].front(), a[i]});
p[i].pop();
}
c[0] = 0;
c[m + 1] = 1e14;
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();
q.push(z);
break;
} else {
len -= q.top().v;
q.pop();
}
}
if (len) {
cout << c[i] - len << "\n";
return;
}
if (q.top().r == i)
q.pop();
q.push({p[d[i]].front(), a[d[i]]});
p[d[i]].pop();
}
}
signed main() {
int T = read();
while (T--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 11ms
memory: 74404kb
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: 8ms
memory: 74008kb
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 12 4 12 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'