Cod sursa(job #1906343)

Utilizator cristimc8Cristi Moldovan cristimc8 Data 6 martie 2017 13:28:46
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("energii.in");
ofstream h("energii.out");

int g, w, n, a[10001], b[10001], cost, energ[100], x;

int main()
{
    f >> g;
    f >> w;
    for(int i = 0; i < g; i++)
    {
        f >> a[i] >> b[i];
    }
    cost = 5002;
    for(int i = 0; i < g; i++)
    if((a[i] >= w) && (b[i] < cost))
    {
        cost = b[i];
        energ[x++] = a[i];
    }
    for(int i = 0; i < g; i++)
    {
        for(int j = 0; j < g; j++)
        {

                if((a[i] + a[j] >= w) && (b[i] + b[j] < cost))
                {
                    cost = b[i] + b[j];
                }
        }
    }
    h << cost;
    return 0;
}