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) {
// TODO implement this function
//k books, sum of A
typedef long long ll;
//x, x+1, x+2, x+3, x+4, x+5... and so on
int extrasum = 0;
for (int x = 0; x < K; x++){
extrasum += x;
}
//we want A <= x*K + extrasum <= 2*A
//x*K + extrasum >= A
//x*K >= A-extrasum
//x >= (A-extrasum)/K
ll target = (A - extrasum)/K + ((A - extrasum)%K != 0);
//to do: check rounding
int l = 1, r = N+1-K, ans = N+1-K;
while (l <= r){
int m = (l+r)/2;
ll res = skim(m);
if (res <= target){
ans = m;
l = m+1;
}
else{
r = m-1;
}
}
ll sum = 0; vector<int> indices;
for (int x = ans; x < ans + K; x++){
sum += skim(x); indices.push_back(x);
}
if (A <= sum && sum <= 2LL*A){
answer(indices);
}
else{
impossible();
}
}
# | 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... |