Cod sursa(job #416805)

Utilizator samuel91Asofronie Samuel samuel91 Data 13 martie 2010 16:01:40
Problema Energii Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#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; 
}