#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
#define BIT(x, i) (((x) >> (i)) & 1)
//#define endl '\n'
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 2002;
pair<int, int> p[N];
ll dp[N][N];
void solve(){
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;
sort(p + 1, p + n + 1, [](auto x, auto y){
return x.second < y.second;
});
for (int i = 0; i <= n; i++){
for (int t = 0; t <= n; t++){
dp[i][t] = 1e18;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++){
auto [w, d] = p[i];
for (int t = 0; t < i; t++){
if (d > t){
dp[i][t + 1] = min(dp[i][t + 1], dp[i - 1][t] + w);
}
}
}
for (int t = n; t >= 1; t--){
ll ans = 1e18;
for (int i = t; i <= n; i++){
ans = min(ans, dp[i][t]);
}
if (ans != 1e18){
cout << t << ' ' << ans << endl;
return;
}
}
}
int main(){
clock_t startTime = clock();
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int test_cases = 1;
// cin >> test_cases;
for (int test = 1; test <= test_cases; test++){
// cout << (solve() ? "YES" : "NO") << endl;
solve();
}
#ifdef LOCAL
cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:63:13: warning: unused variable 'startTime' [-Wunused-variable]
63 | clock_t startTime = clock();
| ^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
30420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
30420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
30420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
30420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |