Cod sursa(job #1906336)

Utilizator cristimc8Cristi Moldovan cristimc8 Data 6 martie 2017 13:25:16
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 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++)
    {
        for(int j = 0; j < g; j++)
        {
            if(a[i] == a[j])
            {
                if((a[i] >= w) && (b[i] < cost))
                {
                    cost = b[i];
                    energ[x++] = a[i];
                }
            }
            else
            {
                if((a[i] + a[j] >= w) && (b[i] + b[j] < cost))
                {
                    cost = b[i] + b[j];
                }
            }
        }
    }
    h << cost;
    return 0;
}