제출 #1343731

#제출 시각아이디문제언어결과실행 시간메모리
1343731Jakub_WozniakA Difficult(y) Choice (BOI21_books)C++20
0 / 100
3 ms444 KiB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define st first
#define nd second
//
// --- 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.
//

const int maxn = (1e+5)+9;
ll tab[maxn];



void solve(int N, int K, long long A, int S) 
{
    // zaloz ze N == S
    for(int i = 1; i <= N ; i++)tab[i] = skim(i);

    ll Skn1 = 0;
    for(int i = 1 ; i < K ; i++)Skn1 += tab[i];

    int Rhr = K;
    while(Rhr <= N && tab[Rhr] + Skn1 < A)Rhr++;


    if(Rhr <= N && tab[Rhr] + Skn1 <= 2*A)
    {
        vector <int> ser ;
        for(int i = 1 ; i < K ; i++)ser.push_back(i);
        ser.push_back(Rhr);
        answer(ser);
        return ;
    }
    if(Rhr == K)
    {
        impossible();
        return ;
    }
    Rhr--;
    
    
    ll Kp = 0 , Ko =0 ;
    for(int i = 1 ; i <= K ; i++)Kp += tab[i];
    for(int i = Rhr ; i > Rhr-K ; i--)Ko += tab[i];

    if(Kp > 2*A)
    {
        impossible();
        return ;
    }
    if(Ko < A)
    {
        impossible();
        return ;
    }


    // K -> Rhr , K-1 -> Rhr-1 , ... , i -> Rhr - (K-i) = Rhr+i-K
    int dod = Rhr-K;
    vector <int> Pt;
    vector <int> ser;
    for(int i = 1; i <= K ; i++)Pt.push_back(i);
    for(int i = max(K + 1 , Rhr - K + 1); i <= Rhr ; i++)Pt.push_back(i);

    for(int l = 0 ; l < Pt.size()-K+1 ; l++)
    {
        ll sum = 0;
        for(int i = 1+l ; i <= K+l ; i++)sum += tab[i];
        if(A <= sum && sum <= 2*A)
        {
            for(int i = 1+l ; i <= K+l ; i++)ser.push_back(i);
            answer(ser);
            return ;
        }
    }

    cout << "NIG\n";
}
#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...