QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#800999 | #9528. New Energy Vehicle | lwj1239 | WA | 2ms | 6056kb | C++11 | 1.7kb | 2024-12-06 17:33:58 | 2024-12-06 17:33:58 |
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);//存储第i个充电站的距离
vector<int> t(N);//存储第i个充电站给谁充电
void solve() {
int n, m;
cin >> n >> m;
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];
s.push({ x[i], t[i] });
}
for (int i = 1; i <= n; i++) {
s.push({INF, 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]];
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: 0ms
memory: 6048kb
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: 2ms
memory: 6056kb
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:
8 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '8'