Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
//#include
using namespace std; typedef long long ll; const int maxn = 1e5 + 10; int n, d; ll p; int v[maxn]; bool check(int x) { priority_queue
pq, greatest; for(int i = 0; i < n; i++) { pq.push(v[i]); } ll sum = 0; for(int i = 1; i <= d; i++) { int max_element = 0; if(!pq.empty()) { max_element = pq.top(); pq.pop(); } sum += max_element; if(i > x) { pq.push(greatest.top()); greatest.pop(); } greatest.push(max_element); } return sum >= p; } int main() { ios_base::sync_with_stdio(false); cin >> n >> p >> d; for(int i = 0; i < n; i++) { cin >> v[i]; } int L = 1, R = d; int res = -1; while(L <= R) { int mid = (L + R) / 2; if(check(mid)) { L = mid + 1; res = max(res, mid); } else { R = mid - 1; } } if(res == d) { cout << "seedno" << endl; } else { cout << res << endl; } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)