#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
bool cmp(pair<int, int> x, pair<int, int> y) {
return x.second < y.second;
}
void solve(int tc) {
int n, k;
cin >> n >> k;
pair<int, int> p[n+1];
for(int i=1; i<=n; i++) cin >> p[i].first >> p[i].second;
sort(p+1, p+1+n, cmp);
pair<int,int> dp[n+1][n+1];
for(int i=1; i<=n; i++) dp[0][i] = {1e18,0};
dp[0][0] = {0,1};
for(int i=1; i<=n; i++) {
for(int j=0; j<i; j++) {
dp[i][j] = {1e18,0};
}
pair<int,int> opt = {1e18,0};
for(int j=0; j<i; j++) {
if(dp[i-1][j].first < opt.first) {
opt.first = dp[i-1][j].first;
opt.second = dp[i-1][j].second;
}
else if(dp[i-1][j].first == opt.first) {
opt.second += dp[i-1][j].second;
}
}
for(int j=i; j<=n; j++) {
if(p[j].second >= i) {
dp[i][j] = opt;
dp[i][j].first += p[j].first;
}
if(dp[i-1][j].first < opt.first) {
opt.first = dp[i-1][j].first;
opt.second = dp[i-1][j].second;
}
else if(dp[i-1][j].first == opt.first) {
opt.second += dp[i-1][j].second;
}
}
}
for(int i=n; i>=1; i--) {
if(dp[i][n].second > 0) {
cout << i << " " << dp[i][n].first << "\n"; return;
}
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
58000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
58000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
58072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
58000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |