Pagini recente » Cod sursa (job #2500359) | Cod sursa (job #2093642) | Cod sursa (job #1235343) | Cod sursa (job #1360185) | Cod sursa (job #2114661)
#include <bits/stdc++.h>
using namespace std;
ofstream fout("peste.out");
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
struct obiect
{
int val, gr;
} o[50002];
struct plasa
{
int p, t;
} v[50002];
priority_queue <int, vector <int>, greater <int> > que;
int n, k, nrob, ttotal;
long long best[50002];
bool d[1002];
inline bool cmp(const plasa a, const plasa b)
{
return a.t<b.t;
}
int main()
{
InParser fin("peste.in");
int i, j, kk, sp=0;
fin>>n>>k>>ttotal;
for(i=1; i<=n; i++)
{
fin>>v[i].p>>v[i].t;
d[v[i].t]=1;
}
sort(v+1,v+n+1,cmp);
for(i=1; i<=n; i++)
{
while(v[i].t==v[i+1].t)
{
sp+=v[i].p;
que.push(v[i].p);
i++;
}
sp+=v[i].p;
que.push(v[i].p);
nrob++;
o[nrob].gr=v[i].t;
while(que.size()>k)
{
sp-=que.top();
que.pop();
}
o[nrob].val=sp;
}
for(i=1; i<=ttotal; i++)
for(j=1; j<=nrob && o[j].gr<=i; j++)
best[i]=max(max(best[i],best[i-o[j].gr]+(long long)o[j].val),best[i-1]);
fout<<best[ttotal]<<'\n';
return 0;
}