Pagini recente » Cod sursa (job #3199208) | Cod sursa (job #139200) | Cod sursa (job #69256) | Cod sursa (job #2815561) | Cod sursa (job #853209)
Cod sursa(job #853209)
#include<fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int w[5001],p[5001],i,n,G,aux,ok,j;
float s1,s;
int main()
{
f>>n>>G;
for(i=1;i<=n;i++)
f>>w[i]>>p[i];
do
{
ok=1;
for(i=1;i<n;i++)
if((float)p[i]/w[i]<(float)p[i+1]/w[i+1]) {aux=p[i];
p[i]=p[i+1];
p[i+1]=aux;
aux=w[i];
w[i]=w[i+1];
w[i+1]=aux;
ok=0;}
}while(ok==0);
for(i=1;i<=n;i++)
g<<w[i]<<" "<<p[i]<<endl;
s=0; s1=0;
for(i=1;i<=n;i++) {s=s+w[i]; s1=s1+p[i];
if(s>G) break;}
if(i>=n+1) g<<s1<<" ";
else
s1=s1-p[i]; s=s-w[i]; s1=s1+(G-s)*(float)p[i]/w[i];
g<<s1<<" ";
f.close();
g.close();
return 0;
}