题目大意:Dima要恰好花N元来买两件礼物分别送给四个guardpost中的其中一个的两名guard。
因为题目已经说了:如果有多种情况,输出其中任意一组即可。所以直接拿两名guard要求的两个最低价中最小的相加,再判断其和与N的关系就行了!
#include<stdio.h>
#include<algorithm>
using namespace std;
int main() {
int n,a,b,c,d;
while(~scanf("%d",&n)){
int num=0;//记录符合条件的guardpost的编号
int first,second;//分别记录送给两guard的礼物要花的钱
for(int i=1;i<=4;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
if(min(a,b)+min(c,d)<=n){//两组中都取最小值判断即可
first=min(a,b);
second=n-first;//恰好花N元
num=i;
}
}
if(num)
printf("%d %d %d\n",num,first,second);
else
printf("-1\n");
}
return 0;
}