Pagini recente » Cod sursa (job #2374764) | Cod sursa (job #2074158) | Cod sursa (job #79879) | Cod sursa (job #1623244) | Cod sursa (job #2045462)
#include<fstream>
#include<queue>
#include<algorithm>
using namespace std;
ifstream f("peste.in");
ofstream g("[este.out");
struct plasa
{
int pesti;
int timp;
} a[50003];
bool cmp(plasa a, plasa b)
{
if(a.timp==b.timp)
return a.pesti<b.pesti;
return a.timp<b.timp;
}
class comparare
{
public:
bool operator()(int a, int b)
{
return a>b;
}
};
priority_queue<int, vector<int>, comparare> heap;
int n, k, total, nrp, v[50003], i, j, best[50003];
int main()
{
f>>n>>k>>total;
for(i=1;i<=n;i++)
f>>a[i].pesti>>a[i].timp;
sort(a+1,a+n+1, cmp);
for(i=1;i<=n;i++)
{
heap.push(a[i].pesti);
if(heap.size()<=k)
{
nrp+=heap.top();
}
else heap.pop();
if(v[a[i].timp]<nrp)
v[a[i].timp]=nrp;
}
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
best[i]=max(best[i],best[i-j]+v[j]);
g<<best[total];
}