제출 #425770

#제출 시각아이디문제언어결과실행 시간메모리
425770dualityA Difficult(y) Choice (BOI21_books)C++14
100 / 100
2 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; #include "books.h" map<int,LLI> M; LLI query(int i) { if (M.count(i)) return M[i]; else return M[i] = skim(i+1); } void solve(int N,int K,long long int A,int S) { int i; LLI s = 0; for (i = 0; i < K; i++) s += query(i); if (s > 2*A) impossible(); else if (s >= A) { vi v; for (i = 0; i < K; i++) v.pb(i+1); answer(v); } else { int l = K-1,r = N-1; while (l < r) { int m = (l+r+1) / 2; if (s-query(K-1)+query(m) <= 2*A) l = m; else r = m-1; } if (s-query(K-1)+query(l) >= A) { vi v; for (i = 0; i < K-1; i++) v.pb(i+1); v.pb(l+1); answer(v); } else { s += query(l)-query(K-1); for (i = K-2; i >= 0; i--) { s += query(l-(K-i)+1)-query(i); if (s >= A) break; } if (i < 0) impossible(); else { int p = i; vi v; for (i = 0; i < p; i++) v.pb(i+1); for (i = l-(K-p)+1; i <= l; i++) v.pb(i+1); answer(v); } } } }
#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...