Pagini recente » Cod sursa (job #720702) | Cod sursa (job #2816431) | Cod sursa (job #1786953) | Cod sursa (job #3040851) | Cod sursa (job #2113989)
#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];
int n, k, nrob, ttotal, aux[50002];
long long best[50002];
bool d[1002];
inline bool cmp(const plasa a, const plasa b)
{
if(a.t==b.t)
return a.p<b.p;
return a.t<b.t;
}
inline void add(int valoare, int &sp)
{
int i, mini=INT_MAX, pozmini;
for(i=1; i<=k; i++)
if(aux[i]<mini) mini=aux[i], pozmini=i;
if(aux[pozmini]<valoare)
{
sp=sp-aux[pozmini]+valoare;
aux[pozmini]=valoare;
}
}
int main()
{
InParser fin("peste.in");
int i, j, 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)
{
add(v[i].p,sp);
i++;
}
add(v[i].p,sp);
o[++nrob].gr=v[i].t;
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;
}