Please sign in first.
Submission #1803531
Source Code Expand
#include <bits/stdc++.h>
#ifndef LOCAL
#define cerr dolor_sit_amet
#endif
#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1, 0, -1, 0, 1, -1, 1, -1};
const int DY[] = { 0, 1, 0, -1, 1, -1, -1, 1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }
// ========================================================================= //
const int N = 5222;
struct Man {
int h, p;
};
int n;
Man a[N];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i].h >> a[i].p;
sort(a, a + n, [](Man const& x, Man const& y) {
return x.h + x.p < y.h + y.p;
});
ll d[2][N];
memset(d, 0x3f, sizeof(d));
d[0][0] = 0;
for (int i = 1; i <= n; ++i) {
int i1 = i & 1;
d[i1][0] = 0;
for (int cnt = 1; cnt <= i; ++cnt) {
d[i1][cnt] = d[i1^1][cnt];
if (a[i-1].h >= d[i1^1][cnt-1])
d[i1][cnt] = min(d[i1][cnt], d[i1^1][cnt-1] + a[i-1].p);
}
}
int ans = 0;
for (int i = 0; i <= n; ++i)
if (d[n&1][i] < LINF)
ans = i;
cout << ans << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Zabuton |
| User | SpyCheese |
| Language | C++14 (GCC 5.4.1) |
| Score | 700 |
| Code Size | 1905 Byte |
| Status | AC |
| Exec Time | 19 ms |
| Memory | 384 KiB |
Judge Result
| Set Name | sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 700 / 700 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| sample | sample-01.txt, sample-02.txt, sample-03.txt |
| All | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, sample-01.txt, sample-02.txt, sample-03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01-01.txt | AC | 1 ms | 384 KiB |
| 01-02.txt | AC | 1 ms | 384 KiB |
| 01-03.txt | AC | 2 ms | 384 KiB |
| 01-04.txt | AC | 4 ms | 384 KiB |
| 01-05.txt | AC | 11 ms | 384 KiB |
| 01-06.txt | AC | 11 ms | 384 KiB |
| 01-07.txt | AC | 11 ms | 384 KiB |
| 01-08.txt | AC | 11 ms | 384 KiB |
| 01-09.txt | AC | 11 ms | 384 KiB |
| 01-10.txt | AC | 1 ms | 384 KiB |
| 01-11.txt | AC | 2 ms | 384 KiB |
| 01-12.txt | AC | 6 ms | 384 KiB |
| 01-13.txt | AC | 12 ms | 384 KiB |
| 01-14.txt | AC | 12 ms | 384 KiB |
| 01-15.txt | AC | 12 ms | 384 KiB |
| 01-16.txt | AC | 12 ms | 384 KiB |
| 01-17.txt | AC | 12 ms | 384 KiB |
| 01-18.txt | AC | 12 ms | 384 KiB |
| 01-19.txt | AC | 1 ms | 384 KiB |
| 01-20.txt | AC | 2 ms | 384 KiB |
| 01-21.txt | AC | 9 ms | 384 KiB |
| 01-22.txt | AC | 16 ms | 384 KiB |
| 01-23.txt | AC | 16 ms | 384 KiB |
| 01-24.txt | AC | 16 ms | 384 KiB |
| 01-25.txt | AC | 16 ms | 384 KiB |
| 01-26.txt | AC | 16 ms | 384 KiB |
| 01-27.txt | AC | 16 ms | 384 KiB |
| 01-28.txt | AC | 11 ms | 384 KiB |
| 01-29.txt | AC | 11 ms | 384 KiB |
| 01-30.txt | AC | 11 ms | 384 KiB |
| 01-31.txt | AC | 11 ms | 384 KiB |
| 01-32.txt | AC | 11 ms | 384 KiB |
| 01-33.txt | AC | 11 ms | 384 KiB |
| 01-34.txt | AC | 11 ms | 384 KiB |
| 01-35.txt | AC | 19 ms | 384 KiB |
| 01-36.txt | AC | 19 ms | 384 KiB |
| 01-37.txt | AC | 19 ms | 384 KiB |
| 01-38.txt | AC | 19 ms | 384 KiB |
| 01-39.txt | AC | 19 ms | 384 KiB |
| 01-40.txt | AC | 11 ms | 384 KiB |
| sample-01.txt | AC | 1 ms | 384 KiB |
| sample-02.txt | AC | 1 ms | 384 KiB |
| sample-03.txt | AC | 1 ms | 384 KiB |