Cod sursa(job #2201214)

Utilizator DimaTCDima Trubca DimaTC Data 3 mai 2018 21:44:46
Problema Ghiozdan Scor 42
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<bits/stdc++.h>
#define NMAX 100000
using namespace std;

int d[75250],/*t[1000000][2], */a[20005]/*, p[75250]*/;
int n,g,k,x;

int main() {
//	ifstream cin("t.in");
	ifstream cin("ghiozdan.in");
	ofstream cout("ghiozdan.out");
	cin>>n>>g;
	for (int i=1; i<=n; i++) cin>>a[i];
	sort(a+1,a+1+n, greater<int>());
	for (int i=1; i<=n; i++) {
		for (int j=g-a[i]; j>=1; j--) {
			if (d[j] && (!d[j + a[i]] || d[j + a[i]]>d[j] + 1)) {
				d[j + a[i]] = d[j] + 1;
			//	t[++k][0] = p[j]; t[k][1] = a[i];
			//	p[j + a[i]] = k;
			}
		}
		d[a[i]] = 1; //t[++k][0] = 0; t[k][1] = a[i]; p[a[i]] = k;
	}
	
	for (int i=g; i>=1; i--) {
		if (d[i]) {
			cout<<i<<" "<<d[i]<<'\n'; 
			return 0;
		}
	}
	 //x=p[i];
/*	while (x) {
		cout<<t[x][1]<<"\n"; x = t[x][0];-
	} */
		
	return 0;
}