Cod sursa(job #1905949)

Utilizator arcadie2k@gmail.comArcadie Caldare [email protected] Data 6 martie 2017 11:45:18
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
struct cont{
    int ene, cost;
};
bool cmp(cont x, cont y){
    if(x.ene>y.ene) return true;
    else if(x.cost<y.cost) return true;
    return false;
}
int main(){
    int n, energy;
    cont t[1002];
    fin>>n>>energy;
    for(int i=0; i<n; i++)
        fin>>t[i].ene>>t[i].cost;
    sort(t, t+n, cmp);
    int ace=0, crc=0;
    for(int i=0; i<n && ace<energy; i++){
        ace+=t[i].ene;
        crc+=t[i].cost;
    }
    fout<<crc;
    /*for(int i=0; i<n; i++)
        fout<<t[i].ene<<" "<<t[i].cost<<"\n";*/
    return 0;
}