Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef vector <int> VI;typedef pair <int,int> PII;#define FOR(i,x,y) for(int i = x;i < y;++ i)#define IFOR(i,x,y) for(int i = x;i > y;-- i)#define fi first#define se secondconst int maxn = 100010;int n,k;LL p[maxn],Q;bool work(){priority_queue <LL> q;FOR(i,1,k+1) q.push(p[i]);int num = k,cnt = 1;LL ans = 0;while(!q.empty()){LL u = q.top(); q.pop();if(num < n) q.push(p[++num]);ans += u*cnt;cnt ++;}if(ans > Q) return false;return true;}