제출 #950011

#제출 시각아이디문제언어결과실행 시간메모리
950011PringA Difficult(y) Choice (BOI21_books)C++17
60 / 100
1 ms604 KiB
#include <bits/stdc++.h>

#include "books.h"

using namespace std;
using ll = long long;
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)

//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
//     books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
//     g++ books_sample.cpp sample_grader.cpp
// in this folder.
//

const int MXN = 100005;
ll h[MXN];

int BSH(int l, int r, ll a) {
    while (l + 1 < r) {
        int mid = (l + r) >> 1;
        (skim(mid) >= a ? r : l) = mid;
    }
    return r;
}

void solve(int n, int k, ll a, int s) {
    FOR(i, 1, k + 1) h[i] = skim(i);
    int aa = BSH(0, n + 1, a);
    if (aa != n + 1) {
        ll val = skim(aa);
        ll ans = 0;
        FOR(i, 1, k) ans += h[i];
        ans += val;
        if (ans <= 2 * a) {
            vector<int> v;
            FOR(i, 1, k) v.push_back(i);
            v.push_back(aa);
            answer(v);
            return;
        }
    }
    if (aa < k + 1) {
        impossible();
        return;
    }
    ll ans = 0;
    FOR(i, 1, k + 1) ans += h[i];
    if (ans >= a && ans <= a * 2) {
        vector<int> v;
        FOR(i, 1, k + 1) v.push_back(i);
        answer(v);
        return;
    }
    for (int i = k; i > 0; i--) {
        int id = aa - (k - i) - 1;
        h[id] = skim(id);
        ans -= h[i];
        ans += h[id];
        // cout << i << ' ' << ans << endl;
        if (ans >= a) {
            ans -= h[id];
            // cout << "ANS: " << ans << endl;
            int bb = BSH(k - 1, id, a - ans);
            // cout << bb << endl;
            vector<int> v;
            FOR(j, 1, i) v.push_back(j);
            v.push_back(bb);
            // FOR(j, i + 2, k + 1) v.push_back(aa - k + j - 1);
            FOR(j, id + 1, aa) v.push_back(j);
            answer(v);
            return;
        }
    }
    impossible();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...