Cod sursa(job #168423)

Utilizator sims_glAlexandru Simion sims_gl Data 31 martie 2008 12:53:06
Problema Peste Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define nm 50010
#define mm 1024

int n, m, T, a[mm], c[nm];
vector< pair<int, int> > v;

int main()
{
	freopen("peste.in", "r", stdin);
	freopen("peste.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &T);

	for (int i = 1; i <= n; ++i) {
		int p, t;

		scanf("%d%d", &p, &t);

		v.push_back(make_pair(p, t));
	}

	sort(v.begin(), v.end());

	for (int i = 1; i <= 1000; ++i)
		for (int j = n - 1, k = m; k > 0 && j >= 0; --j)
			if (v[j].second <= i)
				a[i] += v[j].first, --k;

	for (int i = 1; i <= T; ++i)
		for (int j = 1; j <= 1000 && j <= i; ++j)
			if (c[i] < c[i - j] + a[j])
				c[i] = c[i - j] + a[j];

	printf("%d\n", c[T]);

	return 0;
}