bzoj 1029
parent
864f89628c
commit
0591e4af3f
@ -0,0 +1,36 @@
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
#include <queue>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
inline void readInt(int &x)
|
||||
{
|
||||
int ch = x = 0;
|
||||
while (!isdigit(ch = getchar()));
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
}
|
||||
struct abcd
|
||||
{
|
||||
int t1, t2;
|
||||
bool operator<(const abcd& rhs) const
|
||||
{
|
||||
return this->t2 < rhs.t2;
|
||||
}
|
||||
}T[160001];
|
||||
priority_queue<int> heap;
|
||||
int n, now, ans;
|
||||
int main()
|
||||
{
|
||||
readInt(n);
|
||||
for (int i = 0; i < n; i++) readInt(T[i].t1), readInt(T[i].t2);
|
||||
sort(T, T + n);
|
||||
for (int i = 0; i < n; i++)
|
||||
if (now + T[i].t1 <= T[i].t2) heap.push(T[i].t1), now += T[i].t1, ans++;
|
||||
else if (T[i].t1 <= heap.top() && now - heap.top() + T[i].t1 <= T[i].t2)
|
||||
now -= heap.top(),
|
||||
now += T[i].t1,
|
||||
heap.pop(),
|
||||
heap.push(T[i].t1);
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue