Pagini recente » Cod sursa (job #1677076) | Cod sursa (job #1668923) | Cod sursa (job #132242) | Cod sursa (job #56242) | Cod sursa (job #1157328)
#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;
}