The first time this question, but I think it is not rigorous, hoping Sword friends feel the same about the exchange.
https://www.luogu.org/problem/P4053
I write code like this:
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register inline long long read() { char ch = getchar(); long long x = 0, f = 1; while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } struct build { ll a; ll t; } datas [150001]; inline bool cmp (const build &a,const build &b) { return a.t < b.t; } priority_queue <int> q; signed main(){ #ifndef ONLINE_JUDGE freopen ("shit.txt","r",stdin); #endif #ifdef ONLINE_JUDGE #endif int n = read (); for (int i = 1;i <= n;++ i) { datas [i].a = read (); datas [i].t = read (); } sort (datas + 1,datas + 1 + n,cmp); //开始贪心 int nowt = 0 ; LL ANS = 0 , Nowa = 0 ; for ( int I = . 1 ; I <= n-; ++ I) { // actually BFS IF (nowt DATAS + [I] II.A> DATAS [I] .T ) { // do not satisfy it comes out a repair and replacement longest IF (q.empty (!) && q.top ()> DATAS [I] && nowt II.A - q.top () + DATAS [I] II.A <= DATAS [I] .T) { nowt - = q.top (); q.pop (); q.push (DATAS [I] II.A); nowt + = DATAS [I] II.A; } } else { // it is built directly ++ ANS; nowt + = DATAS [I] II.A; q.push (DATAS [I] II.A); } } COUT << ANS << endl; return 0 ; }
But I think it is very metaphysical. I could not say why 2333