---
# System prepended metadata

title: Untitled

---

#include<stdio.h>
#include<stdlib.h>
#define down ((sizeof kachi)/(sizeof(Goods))) //Goods配列の要素数を求める


typedef struct{
	char name[50];
	int weight;
	int value;
	int number;
}Goods;



//値段の高い順（降順）
void sortValue(Goods kachi[])
{
    int m,j;
    Goods temp;
    for(m=0; m<down; m++){
        for(j=m+1; j<down; j++){
            if(kachi[m].value < kachi[j].value){
                temp = kachi[m];
                kachi[m] = kachi[j];
                kachi[j] = temp;
            }
        }
    }
}


int main()
{
    Goods kachi[] ={
        {"a",5,600,2},{"b",12,1500,2},{"c",8,300,2},{"d",2,900,2},{"e",6,400,2}
    }
    
    sortValue(kachi);
    
	int q;
	int a,nokori=0,goukei=0;
    //nupsack<=25kg
    
	while(1){        //無限ループ
    
        //個数が０なら、値段も０
	    for(q=0;q<5;q++){
    		if(kachi[q].number==0){
    			kachi[q].value=0;
    		}
    	}
        
        //ナップザックに入れた重さと残り入る重さを足して25kgを超えないか調べる
    	if((nokori+kachi[a].weight)<=25){
	    	nokori=nokori+kachi[a].weight;
		    goukei=goukei+kachi[a].value;
    		kachi[a].number=kachi[a].number-1;
	    }
	    else{
		    kachi[a].number=0;
    	}


        //無限退避
    	if(kachi[0].number==0 && kachi[1].number==0 && kachi[2].number==0 && kachi[3].number==0 && kachi[4].number==0){
	    	break;
    	}
	
	}
    
    
	printf("%d",goukei);
	return 0;
}