#include <bits/stdc++.h>
#include"books.h"
using namespace std;
using ll = __int128_t;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvp = vector<vpl>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()
/*
void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...)
{
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
fprintf(stderr, "\n");
va_end(args);
exit(0);
}
namespace
{
int N, K, S, sUsed;
long long A;
vector<long long> seq;
}
void impossible()
{
result("Impossible (not checked): %d book(s) skimmed", sUsed);
exit(0);
}
long long skim(int pos)
{
printf("skim(%d): ", pos);
if (pos<1 || pos>N) result("Invalid skim");
printf("%lld\n", seq[pos]);
sUsed++;
if (sUsed>S) result("Out of books to skim");
return seq[pos];
}
void answer(vector<int> v)
{
printf("answer({");
for(int i = 0; i < (int) v.size(); ++i)
{
printf("%d", v[i]);
if(i + 1 != (int) v.size()) printf(", ");
}
printf("})\n");
if ((int) v.size() != K) result("Invalid answer");
long long sum = 0;
for(auto x: v) {
if (x<1 || x>N) result("Invalid answer");
sum += seq[x];
}
if (sum < A || 2*A<sum) result("Wrong answer");
result("Correct: %d book(s) skimmed", sUsed);
exit(0);
}
*/
vll pas;
ll ski(ll a){
if(pas[a]==-1)return pas[a]=skim(a);
return pas[a];
}
void solve(int n, int k, long long a, int Q) {
ll s = 1, e = n, m;
pas = vll(n+1,-1);
while(s<e){
m = (s+e+1)/2;
ll t = ski(m);
if(t>a)e=m-1;
else s=m;
}
vll v1(k), v2;
vector<int> id;
ll v3=-1;
for(ll i = 0; i < k; ++i){v1[i] = ski(i+1);}
for(ll i = max<ll>(1, s-k+1); i <= s; ++i){v2.pb(ski(i));id.pb(i);}
if(s<n)v3=ski(s+1);
ll p1=0, p2=0;
for(ll i:v1)p1+=i;
for(ll i:v2)p2+=i;
if(p1>2*a)impossible();
else if(k<=s){
if(p2>=a){
for(ll i = 0; i < k; ++i){
if(p2<=2*a)break;
id[i]=i+1;
p2 += v1[i]-v2[i];
}
answer(id);
}
else if(s<n){
iota(all(id),1);
id.back()=s+1;
if(p1-v1.back()+v3<=a*2)answer(id);
else impossible();
}
else impossible();
}
else{
iota(all(id),1);
if(p1>=a)answer(id);
else impossible();
}
}
/*int main()
{
if(scanf("%d %d %lld %d", &N, &K, &A, &S) != 4)
result("Invalid input");
seq.resize(N + 1);
for(int i = 1; i <= N; ++i) {
if(scanf("%lld", &(seq[i])) != 1) result("Invalid input");
if(i>1 && seq[i]<=seq[i-1]) result("Invalid input");
}
solve(N, K, A, S);
result("No answer");
}
*/
# | 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... |