QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#769984 | #9528. New Energy Vehicle | kirco | WA | 104ms | 69028kb | C++23 | 1.9kb | 2024-11-21 20:09:59 | 2024-11-21 20:10:00 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define pb push_back
#define pii pair<int,int>
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
const int N = 100005;
vector<int> a(N);
vector<int> r(N);
vector<int> x(N);
vector<int> t(N);
void solve() {
int n, m;
cin >> n >> m;
queue<int> yxj[n + 1]; //每个电瓶用一个队列存储优先级,即充电站位置
priority_queue<pii, vector<pii>, greater<pii>> s;// 按照pair的第一个键值升序排列的最小堆
for (int i = 1; i <= n; i++) {
cin >> a[i];
r[i] = a[i];
}
for (int i = 1; i <= m; i++) {
cin >> x[i] >> t[i];
yxj[t[i]].push(x[i]);
}
for (int i = 1; i <= n; i++) {
yxj[i].push(MOD); //给所有电瓶都设置一个极大位置的充电站
}
for (int i = 1; i <= n; i++) {
int f = yxj[i].front();
yxj[i].pop();
s.push({f, i});
}
int ans = 0 ;
for (int i = 1; i <= m; i++) {
int len = x[i] - x[i - 1]; //当前充电站与上一站的距离
while (len > 0) { //按照优先队列的顺序用电
if (s.empty())break;
auto top = s.top();
s.pop();
if (a[top.second] == 0)continue;
if (a[top.second] <= len) {
len -= a[top.second];
a[top.second] = 0;
} else {
a[top.second] -= len;
len = 0;
break;
}
}
if (len > 0) {//如果电量不足以到达充电站
ans += (x[i] - x[i - 1] - len);
break;
} else { //给电瓶充电
a[t[i]] = r[t[i]];
int fi = MOD, se = t[i];
if (!yxj[t[i]].empty()) {
fi = yxj[t[i]].front();
yxj[t[i]].pop();
}
s.push({fi, se});
ans += x[i] - x[i - 1];
}
}
for (int i = 1; i <= n; i++) {
ans += a[i]; //如果有剩余电量,增加到ans中
}
cout << ans << endl;
}
signed main() {
cin.tie(0)->ios::sync_with_stdio(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 6052kb
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: 2ms
memory: 6180kb
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: 104ms
memory: 69028kb
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:
811955 1201669 909927 957066 1059944 1128072 662052 868520 758925 698967
result:
wrong answer 1st lines differ - expected: '1543020', found: '811955'