# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
942952 | salmon | Portals (BOI14_portals) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
void solve(int N, int K, long long A, int S) {
long long int lst[20];
long long int sum = 0;
for(int i = 1; i <= K; i++){
lst[i] = skim(i);
sum += lst[i];
}
if(sum >= A * 2){
impossible();
}
else if(sum >= A){
vector<int> v;
for(int i = 1; i <= K; i++){
v.push_back(i);
}
answer(v);
}
else{
vector<int> v;
int s = 1;
int e = N + 1;
while(s != e){
int m = (s + e) / 2;
if(skim(m) >= A){
e = m;
}
else{
s = m + 1;
}
}
if(s != N + 1){
long long int tomp = skim(s);
if(sum - lst[K] + tomp <= A * 2){
for(int i = 1; i <= K - 1; i++){
v.push_back(i);
}
v.push_back(s);
answer(v);
return;
}
N = tomp - 1;
}
set<int> sat;
for(int i = 1; i <= K; i++){
sat.insert(i);
}
for(int i = 0; i < K; i++){
sat.erase(K - i);
sat.insert(N - i);
sum -= lst[K - i];
sum += skim(N - i);
if(A <= sum && sum <= A * 2){
for(int i : sat){
v.push_back(i);
}
answer(v);
return;
}
}
impossible();
}
}