Pagini recente » Cod sursa (job #840090) | Cod sursa (job #1216988) | Cod sursa (job #2970038) | Cod sursa (job #1186619) | Cod sursa (job #1139882)
#include<fstream>
using namespace std;
const int MAX = 10004;
int x[MAX], y[MAX];
int main()
{
int G, W, i, j, sumX = 0, sumY = 0, suma = 0, max = 0;
ifstream g("energii.in");
ofstream f("energii.out");
g >> G >> W;
for (i = 0; i < G; i++)
{
g >> x[i];
g >> y[i];
suma += x[i];
if (y[i] > max)
max = y[i];
}
if (suma < W)
f << "-1";
else
{
for (i = 0; i < G; i++)
{
for (j = i + 1; j < G; j++)
{
if (x[i] < x[j])
{
swap(x[i], x[j]);
swap(y[i], y[j]);
}
}
}
sumX = x[0];
sumY = y[0];
for (i = G - 1; i >= 0; i--)
{
if (sumX + x[i] <= W)
{
sumX += x[i];
sumY += y[i];
}
}
f << sumY;
}
}