Mai intai trebuie sa te autentifici.
Cod sursa(job #944098)
Utilizator | Data | 27 aprilie 2013 13:23:59 | |
---|---|---|---|
Problema | Energii | Scor | 5 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.93 kb |
#include <cstdio>
#include<cstring>
using namespace std;
int d1[5005],d2[5005];
int min(int a,int b)
{
if(a>b)
return b;
return a;
}
int main()
{
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
int g,E,i,j,e,c;
scanf("%d%d",&g,&E);
scanf("%d%d",&e,&c);
for(j=1;j<=E;j++)
if(e>=j)
d1[j]=c;
else
d1[j]=-1;
memcpy(d2,d1,sizeof(d1));
for(i=2;i<=g;i++)
{
scanf("%d%d",&e,&c);
for(j=1;j<=E;j++)
if(e>=j)
if(d2[j]==-1)
d1[j]=c;
else
d1[j]=min(c,d2[j]);
else
if(d2[j-e]!=-1)
d1[j]=min(c+d2[j-e],d2[j]);
else
d1[j]=-1;
memcpy(d2,d1,sizeof(d1));
}
printf("%d",d2[E]);
return 0;
}