QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769354 | #9730. Elevator II | mapleKing | WA | 0ms | 3552kb | C++20 | 1.6kb | 2024-11-21 17:16:28 | 2024-11-21 17:16:28 |
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 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({a[p].first, a[p].second});
p++;
}
while(p < n){
if (q.size() && q.top().y >= f){
node cur = q.top();
q.pop();
ans += cur.y - cur.x;
f = cur.y;
while(p < n && a[p].first <= f){
q.push({a[p].first, a[p].second});
p++;
}
}else{
ans += a[p].second - f;
f = a[p].second;
p++;
while(p < n && a[p].first <= f){
q.push({a[p].first, a[p].second});
p++;
}
}
}
while(q.size()){
node cur = q.top();
q.pop();
ans += cur.y - cur.x;
}
std::cout << ans << "\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: 3552kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
11 5
result:
wrong answer Integer parameter [name=a_i] equals to 5, violates the range [1, 4] (test case 1)