-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25048.cpp
41 lines (34 loc) · 997 Bytes
/
25048.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5;
const ll LIMIT = 1e18;
void solve(){
int N; cin >> N;
pair<ll,ll> arr[N];
for (int i = 0; i < N; i++) cin >> arr[i].first >> arr[i].second;
ll dp[N][MAX+2]; memset(dp, 0, sizeof(dp));
for (int i = 0; i < N; i++) for (int j = 0; j <= MAX+1; j++) dp[i][j] = LIMIT;
for (int i = 0; i < N; i++) {
auto [x,y] = arr[i];
x--;
dp[i][x] = y;
if (i == 0) continue;
x--;
for (int j = 0; j <= MAX; j++) {
dp[i][j] = min(dp[i][j], dp[i-1][j]);
if (j - x >= 0) dp[i][j] = min({dp[i][j], dp[i-1][j-x]+y});
}
}
int computers; cin >> computers;
ll result = dp[N-1][computers];
if (computers == 1) result = 0;
result = result == LIMIT ? -1 : result;
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}