Pagini recente » Cod sursa (job #2075188) | Cod sursa (job #2306981) | Cod sursa (job #1139260) | Cod sursa (job #3236312) | Cod sursa (job #2342088)
#include <fstream>
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
const int N=10005, MAX=1000000000;
int n, k, maxi, mini=MAX;
int profit[N], p[N], g[N];
void citire()
{
in>>n>>k;
for(int i=1; i<=k; i++)
{
in>>g[i]>>p[i];
maxi=max(maxi, g[i]);
}
}
int main()
{
citire();
for(int i=1; i<=k+maxi; i++) profit[i]=MAX;
for(int i=1; i<=n; i++)
for(int j=k-1; j>=0; j--)
if(profit[j]!=MAX && profit[j]+p[i]<profit[j+g[i]]) profit[j+g[i]]=profit[j]+p[i];
for(int i=k; i<=k+maxi; i++) mini=min(mini, profit[i]);
if(mini==MAX) out<<-1;
else out<<mini;
return 0;
}