Submission #411314

#TimeUsernameProblemLanguageResultExecution timeMemory
411314ronnithA Difficult(y) Choice (BOI21_books)C++14
0 / 100
1 ms584 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; void solve(int N, int K, long long A, int S) { int lx = 1, rx = N; vector<int> val(N + 1, -1); int pos = N; while (lx <= rx) { int g = lx + (rx - lx) / 2; val[g] = skim(g); if (val[g] < A) { lx = g + 1; } else { pos = g; rx = g - 1; } } for (int i = 1;i <= K;i ++) val[i] = skim(i); for (int i = pos - 1;i >= max(pos - K, 0);i --) val[i] = skim(i); if (pos < K) { impossible(); return; } if (pos != -1 && pos >= K) { int sm = 0; vector<int> ans; for (int i = 1;i <= K - 1;i ++) { sm += val[i]; ans.push_back(i); } ans.push_back(pos); if (sm + val[pos] >= A && sm + val[pos] <= 2 * A) { answer(ans); return; } } vector<int> ind; vector<int> values; ind.push_back(-1); values.push_back(-1); for (int i = 1;i <= K;i ++) { values.push_back(val[i]); ind.push_back(i); } for (int i = max(pos - K, K + 1);i < pos;i ++) { values.push_back(val[i]); ind.push_back(i); } for (int i = 1;i <= K + 1;i ++) { if ((int)values.size() - i >= K) { int sm = 0; vector<int> ans; for (int j = 0;j < K;j ++) { sm += values[i + j]; ans.push_back(ind[i + j]); } if (sm >= A && sm <= 2 * A) { 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...