# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
447471 | prvocislo | A Difficult(y) Choice (BOI21_books) | C++17 | 2 ms | 1032 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"
typedef long long ll;
using namespace std;
vector<ll> b;
ll query(int i)
{
if (b[i] == -1) b[i] = skim(i+1);
return b[i];
}
void solve(int n, int k, ll a, int s)
{
b.assign(n, -1);
int lo = 0, hi = n;
while (lo < hi)
{
int mid = (lo+hi)/2;
if (query(mid) >= a) hi = mid;
else lo = mid + 1;
}
int m = lo;
if (lo != n)
{
ll sum = query(m);
for (int i = 0; i < k-1; i++) sum += query(i);
if (a <= sum && sum <= 2*a)
{
vector<int> v;
for (int i = 0; i < k-1; i++) v.push_back(i+1);
v.push_back(m+1);
answer(v);
return;
}
}
vector<pair<ll, int> > v;
for (int i = 0; i < min(k, m); i++) v.push_back({query(i), i});
for (int i = max(0, m-k); i < m; i++)
v.push_back({query(i), i});
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = 0; i+k-1 < v.size(); i++)
{
ll sum = 0; vector<int> in;
for (int j = i; j < i+k; j++)
{
sum += v[j].first;
in.push_back(v[j].second+1);
}
if (a <= sum && sum <= 2*a) answer(in);
}
impossible();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |