P2095 nutrition, diet

Title Description

Mr.L is completing its SFI.

To gain weight, Mr.L want to eat more fat. But we can not eat high-fat foods, in which case it will lead to a lack of other nutrients. Mr.L through the study found: the real nutritional and dietary provisions of certain types of foods should not eat more than a one-time number of copies. For example, it is a meal, the meat should not eat more than one part, the fish should not eat more than one part, eggs should not eat more than one part, vegetables should not eat more than two copies. Mr.L want to eat more fat in the case of nutritional diet, of course Mr.L food intake is limited.

Input Format

The first line contains three positive integer n (n≤200), m (m≤100) and k (k≤100). It represents up parts can eat meals Mr.L food m, while n kinds of food for Mr.L choose which kinds of food n into k classes. The second line contains no more than 10 k a positive integer representing the maximum number of copies can eat food of 1 to k. The next n lines each include two positive integers, respectively, of the food fat index ai and bi belongs to the category, wherein ai≤100, bi≤k.

Output Format

That includes a digital Mr.L can eat and maximum fat index.

Sample input and output

Input # 1
6 6 3
3 3 2
15 1
15 2
10 2
15 2
10 2
5 3
Output # 1
60

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
int b[10610],ans;
struct tt{
    int y,z;
}a[10610];
int cmp(const tt &a,const tt &b){
    return a.y>b.y;
}
int read(){
	int a=0,b=1;
	char ch=getchar();
	while((ch<48||ch>57)&&ch!='-'){
		ch=getchar();
	}
	if(ch=='-'){
		b=-1;
		ch=getchar();
	}
	while(ch<48||ch>57){
		ch=getchar();
	}
	while(ch>47&&ch<58){
		a=a*10+ch-48;
		ch=getchar();
	}
	return a*b;
}
int main(){
    int n,m,k;
    n=read(),m=read(),k=read();
    for(int i=1;i<=k;i++){
        b[i]=read();
    }
    for(int i=1;i<=n;i++){
    	a[i].y=read(),a[i].z=read();
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        if(b[a[i].z]>0&&m>0){
            b[a[i].z]--;
            m--;
            ans+=a[i].y;
        }
    }
    printf("%d",ans);
    return 0;
} 

  

Guess you like

Origin www.cnblogs.com/xiongchongwen/p/11517977.html