Test instructions
is not very good explanation, anyway the Chinese topic will not write is not very good explanation, anyway the Chinese question will not write
Analysis:
The larger the cache, the more we can get the largest number, and then make its contribution smaller to find that the larger the cache, the more we will be able to take out the largest number and make its contribution smaller.
So there's a monotonically decreasing nature, and as the cache gets bigger, there's monotonically diminishing, as the cache gets bigger.
Then the direct binary cache size, priority queue simulation can then direct two-point cache size, priority queue simulation can be
Code:
Created by Taosama on 2016-03-06//Copyright (c) Taosama.
All rights reserved. #pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> # Include <iostream> #include <map> #include <queue> #include <string> #include <set> #
Include <vector> using namespace std; #define PR (x) cout << #x << "=" << x << "" #define PRLN (x) cout << #x << "=" <
;< x << Endl const int N = 1e5 +, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
typedef long Long LL;
int n, a[n];
LL Q;
BOOL Check (int x) {priority_queue<int> q;
LL ret = 0;
int j = 1;
for (int i = 1; I <= n; ++i) {if (q.size () = = x) {int cur = q.top (); Q.pop ();
RET + = cur * j + +;
} q.push (A[i]); } while (Q.Size ()) {int cur = q.top (); Q.pop ();
RET + = cur * j + +;
} return ret <= Q; } int main () {#ifdef LOCAL freopen ("C:\\users\\taosama\\desktop\\in.txt", "R", stdin);//Freopen ("C:\\users\\taosa
Ma\\desktop\\out.txt "," w ", stdout);
#endif ios_base::sync_with_stdio (0);
scanf ("%d%lld%", &n, &q);
for (int i = 1; I <= n; ++i) scanf ("%d", A + i);
int L = 1, r = 100000;
while (L <= r) {int m = l + R >> 1;
if (check (m)) R = m-1;
else L = m + 1;
} if (L > 100000) L =-1;
printf ("%d\n", L);
return 0; }