最近好弱做什么题目都是做一晚上
这是合肥站炼铜后遗症?
这题就是贪心
我已开始还写了1小时………三分…………….
#include<bits/stdc++.h>
using namespace std;
#define sz(X) ((int)X.size())
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 3e5+5;
struct Node{
int id; ll t, w;
}p[N];
bool cmp1(Node a,Node b) {
if(a.t != b.t) return a.t < b.t;
else return a.id > b.id;
}
int main(){
int n;
while(~scanf("%d",&n)) {
priority_queue<ll,vector<ll>,greater<ll>> Q;
for(int i = 1; i <= n; ++i) {
scanf("%lld %lld",&p[i].t,&p[i].w); p[i].id = i;
}
int ans = INF;
int tmp = 1;
sort(p+1, p+n+1,cmp1);
int fl = 0;
ll ret = 0; ll pre;
for(int i = n; i >= 1; --i) {
if(fl) {
ret += pre - p[i].t;
if(pre == p[i].t) {
tmp ++; Q.push(p[i].w - p[i].t + 1);
continue;
}
pre = p[i].t;
while(!Q.empty()) {
ll x = Q.top();
if(x > ret) break;
Q.pop(); ret -= x; tmp --;
}
ans = min(ans, tmp);
tmp ++; Q.push(p[i].w-p[i].t+1);
}else {
if(p[i].id == 1) {
fl = 1; ans = min(ans, tmp);
pre = p[i].t;
}else {
Q.push(p[i].w-p[i].t+1);
// if(n == 7) printf("%lld %d\n",p[i].t,tmp);
tmp ++;
}
}
}
ret += pre;
while(!Q.empty()) {
ll x = Q.top();
if(x > ret) break;
Q.pop(); ret -= x; tmp --;
}
ans = min(ans, tmp);
printf("%d\n", ans);
}
return 0;
}