Pagini recente » Monitorul de evaluare | Cod sursa (job #2797692) | Cod sursa (job #1493359) | Cod sursa (job #2383197) | Cod sursa (job #3348911)
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nm=15005;
int dp[nm];
struct Cows
{
int x, y;
}v[1005];
signed main()
{
ifstream cin("energii.in");
ofstream cout("energii.out");
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, w, minn=1e9;
cin>>n>>w;
for(int i=1; i<=n; i++)
{
cin>>v[i].x>>v[i].y;
}
for(int i=0; i<nm; i++)
dp[i]=1e9;
dp[0]=0;
for(int i=1; i<=n; i++)
{
for(int j=nm-1; j>=0; j--)
{
if(dp[j-v[i].x]!=1e9)
dp[j]=min(dp[j], dp[j-v[i].x]+v[i].y);
if(j>=w)
minn=min(minn, dp[j]);
}
}
if(minn==1e9)
cout<<-1;
else
cout<<minn;
return 0;
}