CodeForces 366A
来源:互联网 发布:腾讯游戏礼包领取软件 编辑:程序博客网 时间:2024/05/16 12:08
Description
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spendexactlyn rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integersa, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Sample Input
105 6 5 66 6 7 75 8 6 69 9 9 9
1 5 5
106 6 6 67 7 7 74 4 4 48 8 8 8
3 4 6
53 3 3 33 3 3 33 3 3 33 3 3 3
-1
Hint
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int main(){ int j,a[4][4],i,n,ch,ju,ans=0,sum,k,f1=0,f2; memset(a,0,sizeof(a)); cin>>n; for(i=0;i<3;i+=2) { scanf("%d%d",&a[0][i],&a[0][i+1]); ans+=min(a[0][i],a[0][i+1]); } for(i=1;i<4;i++) { sum=0; for(j=0;j<3;j+=2) { scanf("%d%d",&a[i][j],&a[i][j+1]); sum+=min(a[i][j],a[i][j+1]); } if(sum<ans) { f1=i; } ans=min(ans,sum); } if(ans>n) { cout<<"-1"<<endl; } else { cout<<f1+1<<" "<<min(a[f1][0],a[f1][1])<<" "<<n-min(a[f1][0],a[f1][1])<<endl; } return 0;}
- CodeForces 366A
- codeforces-366#--A
- CodeForces-a
- 【Codeforces Round #366 (Div. 2)】Codeforces 705A Hulk
- Codeforces 903A A
- CodeForces 366A - Dima and Guards
- CodeForces 366A Dima and Guards
- CodeForces - 366A Dima and Guards
- CodeForces 366A- Dima and Guards
- Codeforces 366A Dima and Guards 【水题】
- CodeForces 366A:Dima and Guards【水】
- CodeForces - 366A Dima and Guards (模拟)
- CodeForces 366A Dima and Guards
- Codeforces--366A--Dima and Guards
- 【CodeForces】[366A]Dima and Guards
- 【Codeforces】-366A- Dima and Guards
- Codeforces Round #366 (Div. 2) A. Hulk
- 【codeforces 366A Dima and Guards】
- Markdown编辑技巧记录
- 运算符之间的用法与比较
- php 变量值比较注意事项
- ARC 总结
- 24位二进制解析为有符号整数
- CodeForces 366A
- 设计模式(四)
- VC++中编译C出错:error C2143: syntax error : missing ';' before 'type'
- 安装Windows补丁KB947821报错0x8007000d The data is invalid
- UI_01.第一个ios UI
- 多线程模拟实现生产者/消费者模型
- Spark学习之编程进阶——累加器与广播(5)
- Android Scroller原理
- 回顾:Unity 游戏引擎发展历程