标签:最大 输入输出 queue iostream 计划 input 导致 mes ddc
Mr.L正在完成自己的增肥计划。
为了增肥,Mr.L希望吃到更多的脂肪。然而也不能只吃高脂肪食品,那样的话就会导致缺少其他营养。Mr.L通过研究发现:真正的营养膳食规定某类食品不宜一次性吃超过若干份。比如就一顿饭来说,肉类不宜吃超过1份,鱼类不宜吃超过1份,蛋类不宜吃超过1份,蔬菜类不宜吃超过2份。Mr.L想要在营养膳食的情况下吃到更多的脂肪,当然Mr.L的食量也是有限的。
第一行包含三个正整数n(n≤200),m(m≤100)和k(k≤100)。表示Mr.L每顿饭最多可以吃m份食品,同时有n种食品供Mr.L选择,而这n种食品分为k类。第二行包含k个不超过10的正整数,表示可以吃1到k类食品的最大份数。接下来n行每行包括2个正整数,分别表示该食品的脂肪指数ai和所属的类别bi,其中ai≤100,bi≤k。
包括一个数字即Mr.L可以吃到的最大脂肪指数和。
6 6 3 3 3 2 15 1 15 2 10 2 15 2 10 2 5 3
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;
}
标签:最大 输入输出 queue iostream 计划 input 导致 mes ddc
原文地址:https://www.cnblogs.com/xiongchongwen/p/11517977.html