版本比较
【推荐】反悔贪心 学习笔记
正文
增加 5 行删除 5 行
105 行未改动全部展开10610710810911011011111211311311411511611746 行未改动16416516616716816816917017117217317417517617617717817918067 行未改动24824925025125225225325425525625 行未改动105 行未改动全部展开priority_queue<I>q;I main(){ios::sync_with_stdio(0);cin.tie(0); cin>>n;fo(i,1,n)cin>>a[i][1]>>a[i][0]; sort(a+1,a+n+1);fo(i,1,n){ I t=a[i][0]-a[i][1]; I t=a[i][0]-a[i][1]; if(S<=t)S+=a[i][1],q.push(a[i][1]),++ans; else if(q.top()>a[i][1]){ S-=q.top(),S+=a[i][1],q.pop(),q.push(a[i][1]);}} S-=q.top(),S+=a[i][1],q.pop(),q.push(a[i][1]);}} return printf("%d\n",ans),0;}```
## 简单例题:[P5909 [CTSC2007] 挂缀pendant](https://www.luogu.com.cn/problem/P5909)46 行未改动#include<bits/stdc++.h>#define fo(i,a,b) for(I i(a),_ed(b);i<=_ed;++i)using namespace std;using I=int;using LL=long long;using V=void;I n;LL m,S;const I N=1e5+10;pair<LL,LL>a[N];priority_queue<LL>q; pair<LL,LL>a[N];priority_queue<LL>q;I main(){ios::sync_with_stdio(0);cin.tie(0); cin>>n>>m; fo(i,1,n)cin>>a[i].first>>a[i].second; sort(a+1,a+n+1); fo(i,1,n){ if(S+a[i].first+a[i].second<=m)q.push(a[i].second),S+=a[i].second; else if(q.size()&&a[i].second<q.top())S-=q.top(),S+=a[i].second,q.pop(),q.push(a[i].second);} printf("%d\n",q.size()); printf("%d\n",q.size()); return 0;}```
---67 行未改动```cpp#include<bits/stdc++.h>#define fo(i,a,b) for(I i(a),_ed(b);i<=_ed;++i)using namespace std;using I=int;using LL=long long;using V=void;const I N=2.5e5+10; const I N=2.5e5+10;priority_queue<pair<I,I> >q;I n,b[N];LL s,a[N];I main(){ios::sync_with_stdio(0);cin.tie(0); cin>>n;25 行未改动