QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769354#9730. Elevator IImapleKingWA 0ms3552kbC++201.6kb2024-11-21 17:16:282024-11-21 17:16:28

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 17:16:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-11-21 17:16:28]
  • 提交

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;
}

详细

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)