Cod sursa(job #1157328)

Utilizator ionut98Bejenariu Ionut Daniel ionut98 Data 28 martie 2014 13:47:26
Problema Peste Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("peste.in");
ofstream g("peste.out");
int n,tp,i,m,s,j,ok,jult;
struct plase
{
    int x,y;
}a[50001];
int cmp(plase a,plase b)
{
    if(a.x!=b.x)
    return a.x>b.x;
    else
    return a.y>b.y;
}
int cmp2(plase a,plase b)
{
    if(a.y!=b.y)
    return a.y>b.y;
    else
    return a.x>b.x;
}
int main()
{
    f>>n>>m>>tp;
    for(i=1;i<=n;i++)
    f>>a[i].x>>a[i].y;
    sort(a+1,a+n+1,cmp);
    for(i=1;i<=m;i++)
    sort(a+1,a+n+1,cmp2);
    s=0;
    for(j=1;j<=n&&tp>0;j++)
    {
        if(a[j].y<=tp)
        {
            for(i=j;i<=m+j-1;i++)
            s+=a[i].x;
            tp-=a[j].y;
        }
    }
    g<<s;
    return 0;
}