Pagini recente » Borderou de evaluare (job #1601163) | Borderou de evaluare (job #2244825) | Borderou de evaluare (job #917884) | Borderou de evaluare (job #964522) | Cod sursa (job #2614127)
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
const int INF = 2e9;
const int N = 1e3;
const int W = 5e3;
int dp[5 + W];
int main() {
freopen("energii.in", "r", stdin);
freopen("energii.out", "w", stdout);
int n, w;
scanf("%d%d", &n, &w);
for(int i = 1; i <= n; i++) {
int p, g;
scanf("%d%d", &g, &p);
for(int j = W; j >= 0; j--) {
if(dp[j]) {
if(dp[min(w, j + g)] > 0)
dp[min(w, j + g)] = min(dp[min(w, j + g)], dp[j] + p);
else dp[min(w, j + g)] = dp[j] + p;
}
}
if(dp[min(w, g)] > 0)
dp[min(w, g)] = min(dp[min(w, g)], p);
else dp[min(w, g)] = p;
}
if(dp[w]) printf("%d\n", dp[w]);
else printf("-1\n");
return 0;
}