Submission #877597

#TimeUsernameProblemLanguageResultExecution timeMemory
877597andrei_iorgulescuA Difficult(y) Choice (BOI21_books)C++14
100 / 100
1 ms1452 KiB
#include <bits/stdc++.h>
#include "books.h"

using namespace std;

//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
//     books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
//     g++ books_sample.cpp sample_grader.cpp
// in this folder.
//

void solve(int N, int K, long long A, int S)
{
    int st = 0,pas = 1 << 16;
    while (pas != 0)
    {
        if (st + pas <= N and skim(st + pas) <= A)
            st += pas;
        pas /= 2;
    }
    vector<long long>v(N + 1);
    for (int i = 1; i <= K; i++)
        v[i] = skim(i);
    for (int i = max(1,st - K + 1); i <= st; i++)
        v[i] = skim(i);
    if (st != N)
    {
        v[st + 1] = skim(st + 1);
        if (st + 1 >= K)
        {
            long long sum = v[st + 1];
            for (int i = 1; i < K; i++)
                sum += v[i];
            if (sum <= 2 * A)
            {
                vector<int>sol;
                for (int i = 1; i < K; i++)
                    sol.push_back(i);
                sol.push_back(st + 1);
                answer(sol);
                return;
            }
        }
    }
    if (st >= K)
    {
        for (int i = 0; i <= K; i++)
        {
            ///primele i si de la st - K + 1 + i la st
            long long sum = 0;
            for (int j = 1; j <= i; j++)
                sum += v[j];
            for (int j = st - K + 1 + i; j <= st; j++)
                sum += v[j];
            if (sum >= A and sum <= 2 * A)
            {
                vector<int>sol;
                for (int j = 1; j <= i; j++)
                    sol.push_back(j);
                for (int j = st - K + 1 + i; j <= st; j++)
                    sol.push_back(j);
                answer(sol);
                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...