Submission #1017352

#TimeUsernameProblemLanguageResultExecution timeMemory
1017352toast12A Difficult(y) Choice (BOI21_books)C++14
0 / 100
0 ms344 KiB
#include "books.h" #include <vector> #include <iostream> using namespace std; using ll = long long; // // --- 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) { vector<int> a(K+1); vector<ll> books(K); ll sum = 0; for (int i = 1; i <= K; i++) { a[i] = i; books[i] = skim(i); sum += books[i]; } if (sum > 2*A) { impossible(); return; } if (sum >= A && sum <= 2*A) { vector<int> ans(K); for (int i = 1; i <= K; i++) ans[i-1] = a[i]; answer(ans); } int idx = N; for (int i = K; i >= 1; i--) { // move the ith book to the end sum -= books[i]; int x = skim(idx); if (sum+x >= A && sum+x <= 2*A) { a[i] = idx; break; } else if (sum+x < A) { sum += x; books[i] = x; a[i] = idx; idx--; } else { // cout << "HELLO\n"; int l = a[i], r = idx; while (l < r) { int mid = (l+r)/2; int d = skim(mid); if (sum+d >= A && sum+d <= 2*A) { a[i] = mid; break; } if (sum+d < A) { l = mid+1; } else { r = mid; } } a[i] = (l+r)/2; break; } } vector<int> ans(K); for (int i = 1; i <= K; i++) { ans[i-1] = a[i]; } answer(ans); }
#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...