Codeforces 366A:Dima and Guards(水题)

来源:互联网 发布:mac idea 常用快捷键 编辑:程序博客网 时间:2024/05/18 02:45
A. Dima and Guards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n 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 integers a, 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.

Examples
input
105 6 5 66 6 7 75 8 6 69 9 9 9
output
1 5 5
input
106 6 6 67 7 7 74 4 4 48 8 8 8
output
3 4 6
input
53 3 3 33 3 3 33 3 3 33 3 3 3
output
-1
Note

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.


题目大意:为了简单理解题意,就异译下:一个人想进一个女生宿舍找他女朋友,这个宿舍有四个口,每个口有两个门卫,想进去宿舍,你必须得通过某个口进去,要想通过某个口,你就得贿赂两个门卫,输入四行数字,代表四个口,每行四个数字,分别代表门卫1所知道的最便宜的巧克力价格和最便宜的果汁价格,门卫2所知道的最便宜的巧克力价格和最便宜的果汁价格,你随便给他们各买一件礼物即可,不过礼物的价格不能低于他们已知的价格。(PS:可输出任意一种符合情况的答案即可)

代码如下:

#include <stdio.h>#include <algorithm>using namespace std;int main(){int n;scanf("%d",&n);int a[4][4];for(int i=0;i<4;i++){for(int j=0;j<4;j++)scanf("%d",&a[i][j]);}int i;for(i=0;i<4;i++)//扫每个站点 {int xiao1=min(a[i][0],a[i][1]);//找到门卫1所知道的巧克力价格和果汁价格中便宜的一个买给他。 if(n<xiao1)//门卫1所想要的任意一个礼物都大于“我”的钱数,那肯定不行了,找下个站点吧。 {continue;}int xiao2=min(a[i][2],a[i][3]);//找到门卫2所知道的巧克力价格和果汁价格中便宜的一个买给他。if(n-xiao1<xiao2)//剩下的钱也不够给门卫2买东西,那就也得找下个站点 {continue;}printf("%d %d %d\n",i+1,xiao1,n-xiao1);//找到了的话就输出,然后结束。 break;}if(i>=4)printf("-1\n");//找不到。。 return 0;}


0 0