CF366A.Dima and Guards
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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!
自上一轮以来,情况没有任何变化。迪马和因娜依然彼此相爱,渴望相聚。他们已与谢尔盖达成协议,现在需要与宿舍的守卫们达成协议……
迪马的宿舍共有四个岗亭。每个岗亭中有两名守卫(在俄罗斯,这类守卫通常为年长女性)。你可以用一块巧克力或一盒果汁来贿赂一名守卫。对每名守卫,你都知道她所能接受的巧克力的最低价格,以及她所能接受的果汁的最低价格。若赠送给某位守卫的巧克力价格低于该守卫所要求的最低巧克力价格,或赠送给某位守卫的果汁价格低于该守卫所要求的最低果汁价格,则该守卫将拒绝接受这份礼物。
要通过一个岗亭,必须贿赂该岗亭中的两名守卫。
商店中提供任意价格(价格从 1 开始)的果汁和巧克力,且数量无限。迪马希望选择某个岗亭,为该岗亭中的每名守卫各购买一份礼物,并恰好花费 n 卢布。
请帮助他选择一个能让他安全带因娜通过的岗亭;若无法做到,请说明这是不可能的。请注意,因娜听到这个消息会非常难过!
输入格式
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.
输入的第一行包含一个整数 n(1≤n≤105)—— 表示迪马希望花费的钱数。接下来是四行,每行描述一个岗哨。每行包含四个整数 a,b,c,d(1≤a,b,c,d≤105)—— 分别表示第一个守卫所需的巧克力最低价格和果汁最低价格,以及第二个守卫所需的巧克力最低价格和果汁最低价格。
输出格式
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.
在输出的一行中,打印三个以空格分隔的整数:岗哨编号、第一个礼物的费用以及第二个礼物的费用。如果不存在满足条件的岗哨使得迪马能偷偷将因娜带入,则在单独一行中输出 -1。
岗哨按输入中给出的顺序编号为 1 到 4。
若存在多个解,可输出其中任意一个。
输入输出样例
输入#1
10 5 6 5 6 6 6 7 7 5 8 6 6 9 9 9 9
输出#1
1 5 5
输入#2
10 6 6 6 6 7 7 7 7 4 4 4 4 8 8 8 8
输出#2
3 4 6
输入#3
5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
输出#3
-1
说明/提示
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.
第一个样例的解释:
唯一一种花费 10 卢布购买礼物、且每份礼物价格均不低于最低限价的方式,是从第一个岗哨的两名守卫那里各买一块 5 卢布的巧克力。
第二个样例的解释:
Dima 需要为第一个岗哨花费 12 卢布,第二个岗哨 14 卢布,第四个岗哨 16 卢布。因此,唯一可以偷偷溜过的岗哨是第三个岗哨。于是,Dima 可以为第一位守卫买一块 4 卢布的巧克力,为第二位守卫买一瓶 6 卢布的果汁。
输入解题思路,AI测评打分。不知道怎么写?