Pagini recente » Cod sursa (job #3148529) | Cod sursa (job #100514) | Cod sursa (job #3203482) | Cod sursa (job #2582750) | Cod sursa (job #416805)
Cod sursa(job #416805)
#include <fstream>
#define wmax 5005
#define gmax 1005
#define inf 32000
using namespace std;
ifstream f("energii.in");
ofstream gout("energii.out");
struct generator { float e,cost; } g[gmax];
int s[wmax],n,w;
void citire ()
{
f>>n>>w;
for (int i=1; i<=n; i++)
f>>g[i].e>>g[i].cost;
f.close ();
}
int cost ()
{ int i,j,C=0;
float efi,efj,auxc,auxe;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i!=j)
{
efi=g[i].cost/g[i].e;
efj=g[j].cost/g[j].e;
if(efi<efj)
{
auxc=g[i].cost; g[i].cost=g[j].cost; g[j].cost=auxc;
auxe=g[i].e; g[i].e=g[j].e; g[j].e=auxe;
}
}
i=1;
while(w&&i<=n)
{
C+=g[i].cost;
w-=g[i].e;
i++;
}
return C;
}
int main ()
{
citire ();
gout<<-1;
gout.close (); return 0;
}