제출 #812932

#제출 시각아이디문제언어결과실행 시간메모리
812932Ronin13A Difficult(y) Choice (BOI21_books)C++17
100 / 100
2 ms336 KiB
#include <bits/stdc++.h>
#define pb push_back
 
#include "books.h"
 
using namespace std;
//
// --- 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.
//
 
void solve(int n, int k, long long A, int S) {
    // TODO implement this function
    long long x = skim(k - 1);
    if(x >= A){
        impossible();
        return;
    }
    vector <long long > a, b;
    for(int i = 1; i <= k; i++){
        a.pb(skim(i));
    }
    int l = 1, r = n + 1;
    while(l + 1 < r){
        int mid = (l + r) / 2;
        if(skim(mid) >= A) r = mid;
        else l = mid;
    }
    if(r != n + 1){
        long long tot = 0;
        for(int i= 0; i < k - 1; i++){
            tot += a[i];
        }
        tot += skim(r);
        if(tot <= 2 * A){
            vector <int> vv;
            for(int i = 0; i < k - 1; i++)
                vv.pb(i + 1);
            vv.pb(r);
            answer(vv);
            return;
        }
    }
    for(int i = r - 1; i >= r - k; i--){
        b.pb(skim(i));
    }
    for(int i = 0; i <= k; i++){
        long long tot = 0;
        for(int j = 0; j < i; j++) tot += a[j];
        for(int j = 0; j < k - i; j++) tot += b[j];
        if(tot >= A && tot <= 2 * A){
            vector <int> ans;
            for(int j = 0; j < i; j++) ans.pb(j + 1);
            for(int j = 0; j < k - i; j++) ans.pb(r - j - 1);
            answer(ans);
            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...