Pagini recente » Cod sursa (job #1516576) | mircealinkuu | Cod sursa (job #3263055) | Cod sursa (job #571651) | Cod sursa (job #2514071)
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
const string file = "energii";
const ll INF = 9223372036854775807ll;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, inf = 2147483647-20005, nmax = 20005;
int n, G, pd[2][nmax];
int main()
{
ifstream fin (file+".in");
ofstream fout (file+".out");
fin >> n >> G;
for (int i = 0; i < nmax; ++i)
pd[0][i] = inf;
pd[0][0] = 0;
for (int i = 1; i <= n; ++i){
int x, c;
fin >> x >> c;
for (int j = 0; j < nmax; ++j){
pd[i%2][j] = pd[1-(i%2)][j];
if (x <= j)
pd[i%2][j] = min(pd[i%2][j], pd[1-(i%2)][j-x]+c);
}
}
int ans = pd[n%2][G];
for (int i = G+1; i < nmax; ++i)
ans = min(ans, pd[n%2][i]);
fout << ans << "\n";
return 0;
}