Pagini recente » Cod sursa (job #2193982) | Cod sursa (job #1959718) | Cod sursa (job #870076) | Istoria paginii runda/ioi_bil_c2 | Cod sursa (job #2926025)
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
const int maxn=10001;
int n,G;
struct detalii{
int greutate,profit;
};
void sortare(detalii V[])
{
for(int i=0;i<n-1;i++)
for(int j=i;j<n;j++)
if(V[i].profit<V[j].profit)
{
swap(V[i].profit,V[j].profit);
swap(V[i].greutate,V[j].greutate);
}
}
void selectare(detalii V[])
{
int i=0;
int profit=0;
while(G-V[i].greutate>=0)
{
G-=V[i].greutate;
profit+=V[i].profit;
i++;
/// g<<V[i].profit<< " " << V[i].greutate <<'\n';
}
g<<profit;
}
void citire(detalii V[])
{
f>>n>>G;
for(int i=0;i<n;i++)
f>> V[i].greutate >> V[i].profit;
}
int main()
{
detalii V[maxn];
citire(V);
sortare(V);
selectare(V);
f.close();
g.close();
return 0;
}