Submission #34133334
Source Code Expand
/******************************************************/
/******************************************************/
/** **/
/** BISMILLAHIR RAHMANIR RAHIM **/
/** REAZ AHAMMED CHOWDHURY - reaziii **/
/** Department of Computer Science and Engineering **/
/* INSTITUTE OF SCIENCE AND TECHNOLOGY **/
/** **/
/******************************************************/
/******************************************************/
#include<bits/stdc++.h>
#define pcase(x) printf("Case %d: ",x++)
#define fri(f) for(int i=0;i<f;i++)
#define frj(f) for(int j=0;j<f;j++)
#define reset(x) memset(x,-1,sizeof(x))
#define all(x) x.begin(),x.end()
#define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout)
#define infi INT_MAX
#define linfi LLONG_MAX
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mgraph map<int,vector<int> >
#define pb push_back
#define clr(x) memset(x,0,sizeof(x))
#define fro(i,x,y) for(int i=x;i<y;i++)
#define ech(x,a) for(auto &x : a)
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define pi acos(-1.0)
using namespace std;
template<class T> void read(T& x) {cin >> x;}
template<class H, class... T> void read(H& h, T&... t) {read(h); read(t...);}
template<class A> void read(vector<A>& x) {for (auto &a : x) read(a);}
template<class H> void print(vector<H> &x) {ech(a, x) cout << a << " "; cout << endl;}
template<class P> void debug(P h) {
#ifndef ONLINE_JUDGE
cerr << h << " ";
#endif
}
template<class W, class... V> void debug(W h, V... t) {
#ifndef ONLINE_JUDGE
debug(h);
debug(t...);
cerr << endl;
#endif
}
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}
ll bigmod(ll a, ll b, ll mod) {if (b == 0) return 1; if (b == 1) return a; if (b & 1) {return ((a % mod) * (bigmod(a, b - 1, mod) % mod)) % mod;} ll x = bigmod(a, b / 2, mod); return (x * x) % mod;}
ll geti() {ll x; read(x); return x;}
ll cdiv(ll a, ll b) {ll ret = a / b; if (a % b) ret++; return ret;}
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
int dx[4] = { +0, +0, +1, -1};
int dy[4] = { -1, +1, +0, +0};
//................................___Start from here___...............................//
//................................_____________________..............................//
int solve() {
int n;
cin >> n;
vector<pll> arr(n);
fri(n) cin >> arr[i].ff >> arr[i].ss;
sort(arr.begin(), arr.end(), [](pll a, pll b) {
return a.ss + a.ff < b.ff + b.ss;
});
arr.insert(arr.begin(), {0, 0});
ll dp[n + 10][n + 10];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) dp[i][j] = 1e17;
}
dp[0][0] = 0;
ll res = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j];
if (arr[i].ff >= dp[i - 1][j - 1]) {
dp[i][j] = min(dp[i - 1][j - 1] + arr[i].ss, dp[i][j]);
res = j;
}
}
}
cout << res << endl;
return 0;
}
int main(int argc, char* argv[]) {
if (argc <= 1) {
#ifndef ONLINE_JUDGE
input;
output;
#endif
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(0);
#endif
}
int cs = 1, cn = 1;
while (cs--) {
solve();
}
}
Submission Info
| Submission Time |
|
| Task |
D - Zabuton |
| User |
reaz |
| Language |
C++ (GCC 9.2.1) |
| Score |
0 |
| Code Size |
3786 Byte |
| Status |
WA |
| Exec Time |
134 ms |
| Memory |
199444 KiB |
Compile Error
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:125:14: warning: unused variable ‘cn’ [-Wunused-variable]
125 | int cs = 1, cn = 1;
| ^~
./Main.cpp:111:26: warning: unused parameter ‘argv’ [-Wunused-parameter]
111 | int main(int argc, char* argv[]) {
| ~~~~~~^~~~~~
Judge Result
| Set Name |
sample |
All |
| Score / Max Score |
0 / 0 |
0 / 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 |
3524 KiB |
| 01-02.txt |
WA |
1 ms |
3508 KiB |
| 01-03.txt |
AC |
14 ms |
15596 KiB |
| 01-04.txt |
AC |
35 ms |
49840 KiB |
| 01-05.txt |
AC |
130 ms |
199204 KiB |
| 01-06.txt |
AC |
129 ms |
199412 KiB |
| 01-07.txt |
AC |
130 ms |
199308 KiB |
| 01-08.txt |
WA |
132 ms |
199444 KiB |
| 01-09.txt |
AC |
129 ms |
199376 KiB |
| 01-10.txt |
AC |
3 ms |
3476 KiB |
| 01-11.txt |
AC |
11 ms |
10268 KiB |
| 01-12.txt |
AC |
57 ms |
73440 KiB |
| 01-13.txt |
AC |
123 ms |
187648 KiB |
| 01-14.txt |
AC |
129 ms |
199208 KiB |
| 01-15.txt |
AC |
129 ms |
199400 KiB |
| 01-16.txt |
WA |
131 ms |
199308 KiB |
| 01-17.txt |
AC |
130 ms |
199412 KiB |
| 01-18.txt |
AC |
130 ms |
199432 KiB |
| 01-19.txt |
AC |
2 ms |
3584 KiB |
| 01-20.txt |
AC |
9 ms |
8160 KiB |
| 01-21.txt |
AC |
73 ms |
97264 KiB |
| 01-22.txt |
AC |
131 ms |
198360 KiB |
| 01-23.txt |
AC |
130 ms |
199276 KiB |
| 01-24.txt |
AC |
133 ms |
199308 KiB |
| 01-25.txt |
AC |
130 ms |
199280 KiB |
| 01-26.txt |
AC |
132 ms |
199308 KiB |
| 01-27.txt |
AC |
131 ms |
199292 KiB |
| 01-28.txt |
AC |
131 ms |
199296 KiB |
| 01-29.txt |
AC |
132 ms |
199308 KiB |
| 01-30.txt |
AC |
128 ms |
199376 KiB |
| 01-31.txt |
WA |
130 ms |
199364 KiB |
| 01-32.txt |
WA |
129 ms |
199408 KiB |
| 01-33.txt |
AC |
130 ms |
199300 KiB |
| 01-34.txt |
AC |
129 ms |
199408 KiB |
| 01-35.txt |
AC |
133 ms |
199208 KiB |
| 01-36.txt |
AC |
131 ms |
199400 KiB |
| 01-37.txt |
AC |
134 ms |
199212 KiB |
| 01-38.txt |
AC |
132 ms |
199336 KiB |
| 01-39.txt |
AC |
133 ms |
199304 KiB |
| 01-40.txt |
AC |
129 ms |
199400 KiB |
| sample-01.txt |
AC |
2 ms |
3576 KiB |
| sample-02.txt |
AC |
2 ms |
3584 KiB |
| sample-03.txt |
AC |
2 ms |
3608 KiB |