QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769359 | #9730. Elevator II | mapleKing | WA | 0ms | 3532kb | C++20 | 1.8kb | 2024-11-21 17:18:59 | 2024-11-21 17:18:59 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize(2)
// using namespace std;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
struct node
{
int id, x, y;
friend bool operator < (node a, node b){
return a.y < b.y;
}
};
void solve() {
int n, f;
std::cin >> n >> f;
std::vector<std::pair<int, int>> a(n);
for(auto &[x, y] : a){
std::cin >> x >> y;
}
i64 ans = 0;
std::sort(a.begin(), a.end());
std::priority_queue<node> q;
int p = 0;
while(p < n && a[p].first <= f){
q.push({p + 1, a[p].first, a[p].second});
p++;
}
std::vector<int> res;
while(p < n){
if (q.size() && q.top().y >= f){
node cur = q.top();
q.pop();
ans += cur.y - cur.x;
res.push_back(cur.id);
f = cur.y;
while(p < n && a[p].first <= f){
q.push({a[p].first, a[p].second});
p++;
}
}else{
res.push_back(p + 1);
ans += a[p].second - f;
f = a[p].second;
p++;
while(p < n && a[p].first <= f){
q.push({p + 1, a[p].first, a[p].second});
p++;
}
}
}
while(q.size()){
node cur = q.top();
q.pop();
ans += cur.y - cur.x;
res.push_back(cur.id);
}
std::cout << ans << "\n";
for(auto x : res){
std::cout << x << " ";
}
std::cout << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// std::cout << std::fixed << std::setprecision(10); // 固定输出精度
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3532kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
-5 2 1 3 5 5 2 1
result:
wrong answer Integer parameter [name=cost] equals to -5, violates the range [0, 10^18] (test case 1)