Cod sursa(job #2202227)

Utilizator _Victor_Victor Ciobanu _Victor_ Data 7 mai 2018 23:45:37
Problema Ghiozdan Scor 42
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <bits/stdc++.h>

using namespace std;

int G[75000],N[75000];
short V[20000];

int main(){
	int n,g;
	ifstream fin("ghiozdan.in");
	ofstream fout("ghiozdan.out");
	fin>>n>>g;
	for (int i=0;i<n;i++) fin>>V[i];
	for (int i=0;i<n;i++){
		for (int j=g;j>=V[i];j--){
		 if(G[j-V[i]]+V[i]>G[j]|| G[j-V[i]]+V[i]==G[j] && N[j-V[i]]+1<N[j]){
		 	 	G[j]=G[j-V[i]]+V[i];
		 	 	N[j]=N[j-V[i]]+1;
		 	}	
		}
	} 
	fout<<G[g]<<' '<<N[g];
	return 0;
}