Cod sursa(job #2204461)

Utilizator _Victor_Victor Ciobanu _Victor_ Data 15 mai 2018 22:51:50
Problema Ghiozdan Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>

using namespace std;

int G[75000],N[75000];//,G2[75000],N2[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--){
		 int p = j-V[i];
		 if(G[p]>G[j] || (G[p]+V[i]==G[j] && N[p]+1<N[j])){
		 	 	G[j]=G[p]+V[i];
		 	 	N[j]=N[p]+1;
		 	}	
		}
		//for(int j=1;j<=g;j++)
		//	cout<<G[j]<<' ';
		//cout<<'\n';
	} 
	fout<<G[g]<<' '<<N[g]<<'\n';
	return 0;
}