Pagini recente » Cod sursa (job #1394303) | Cod sursa (job #866736) | Cod sursa (job #1719968) | Cod sursa (job #1300282) | Cod sursa (job #652430)
Cod sursa(job #652430)
/*
* File: main.c
* Author: mihai
*
* Created on December 23, 2011, 11:47 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define max(a, b) (a) > (b) ? (a) : (b)
/*
*
*/
int main(int argc, char** argv) {
freopen("ghiozdan.in", "r", stdin);
freopen("ghiozdan.out", "w", stdout);
int i, j, k, x, gmax = 0, ss = 0;
int *c = (int*) calloc (201, sizeof(int));
int *s = (int*) calloc (75000, sizeof(int));
int *t = (int*) calloc (75000, sizeof (int));
const int n, g;
scanf("%d %d", &n, &g);
for (i = 0; i < n; i++) {
scanf("%d", &x);
c[x]++;
if (x > gmax) gmax = x;
}
s[0] = 1;
for (i = gmax; i; --i)
if (c[i])
for (j = g - i; j >= 0; --j)
if (s[j])
for (k = 1; k <= c[i] && j + k * i <= g && !s[j + k * i]; ++k) {
s[j + k * i] = s[j + (k - 1) * i] + 1;
t[j + k * i] = i;
if (j + k * i > ss)
ss = j + k * i;
}
--s[ss];
printf("%d %d\n", ss, s[ss]);
for (i = ss; i; i -= t[i])
printf("%d\n", t[i]);
return 0;
}