QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#787406#9730. Elevator IIxyggzsfWA 0ms3760kbC++141.6kb2024-11-27 11:33:372024-11-27 11:33:48

Judging History

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

  • [2024-11-27 11:33:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3760kb
  • [2024-11-27 11:33:37]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
#define int    long long 
typedef pair<int, int>pii;
typedef pair<char, int>pci;
typedef pair<pii, int>piii;
const int mod = 998244353;
const int N = 5e5 + 100;

void solve()
{
    vector<piii>a;
    vector<bool> st;
    int n, h; cin >> n >> h;
    for (int i = 1; i <= n; i++) {
        int t1, t2;
        cin >> t1 >> t2;
        a.push_back({ { t1,t2 }, i });
        st.push_back(false);
    }
    sort(a.begin(), a.end());

    int sum = 0;

    int start = -1;
    int now_h = h;
    for (int i = 0; i < n; i++) {
        if (a[i].first.first > h) break;
        if (a[i].first.second > now_h)
        {
            now_h = max(now_h, a[i].first.second);
            start = i;
        }
    }

    if (start == -1) {
        sum += a[0].first.first - h;
        start = 0;
    }
  
    st[start] = true;
    for (int i = start + 1; i < n; i++) {
        if (a[i].first.second <= now_h) continue;
        sum += max(a[i].first.first - now_h, (int)0);
        now_h = a[i].first.second;

        st[i] = true;
    }

    for (auto t : a) {
        sum += t.first.second - t.first.first;
    }
    cout << sum << endl;

    for (int i = 0; i < n; i++) {
        if (st[i]) cout << a[i].second << ' ';
    }
    for (int i = n - 1; i >= 0; i--) {
        if (!st[i]) cout << a[i].second << ' ';
    }
    cout << endl;

}

signed main()
{
    ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3760kb

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:

11
3 4 1 2 
2
1 2 

result:

wrong answer Participant declares the cost to be 2, but the plan actually costs 6 (test case 2)