• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #214 Div2 A

A. Dima and Guards
time limit per test 1 second
memory limit per test 256 megabytes
 

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.

Sample test(s)
Input
10 
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10 
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5 
3 3 3 3
3 3 3 3
3 3 3 3
3 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 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <set>
 5 #include <cstring>
 6 #include <string>
 7 #include <map>
 8 #include <cmath>
 9 #include <ctime>
10 #include <algorithm>
11 #include <queue>
12 
13 using namespace std;
14 #define INF 0x7fffffff
15 #define mod 1000000007
16 #define maxm 1001
17 #define mp make_pair
18 #define pb push_back
19 #define rep(i,n) for(int i = 0; i < (n); i++)
20 #define re return
21 #define fi first
22 #define se second
23 #define sz(x) ((int) (x).size())
24 #define all(x) (x).begin(), (x).end()
25 #define sqr(x) ((x) * (x))
26 #define sqrt(x) sqrt(abs(x))
27 #define y0 y3487465
28 //#define y1 y8687969
29 #define fill(x,y) memset(x,y,sizeof(x))
30 
31 typedef vector<int> vi;
32 typedef long long ll;
33 typedef long double ld;
34 typedef double D;
35 typedef pair<int, int> ii;
36 typedef vector<ii> vii;
37 typedef vector<string> vs;
38 typedef vector<vi> vvi;
39 
40 template<class T> T abs(T x) { re x > 0 ? x : -x; }
41 
42 const int maxn = 115;
43 int n, m, t, k,ans;
44 //string s;
45 int main(){
46     int a, b, c, d;
47     scanf("%d", &n);
48     for (int i = 1; i <= 4; i++){
49         scanf("%d%d%d%d", &a, &b, &c, &d);
50         a = min(a, b); c = min(c, d); 
51         if (a+c <= n){printf("%d %d %d\n", i, a, n-a); return 0;}
52     }
53     printf("-1\n");
54     return 0;
55 }
View Code
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <set>
 5 #include <cstring>
 6 #include <string>
 7 #include <map>
 8 #include <cmath>
 9 #include <ctime>
10 #include <algorithm>
11 #include <queue>
12 
13 using namespace std;
14 #define INF 0x7fffffff
15 #define mod 1000000007
16 #define maxm 1001
17 #define mp make_pair
18 #define pb push_back
19 #define rep(i,n) for(int i = 0; i < (n); i++)
20 #define re return
21 #define fi first
22 #define se second
23 #define sz(x) ((int) (x).size())
24 #define all(x) (x).begin(), (x).end()
25 #define sqr(x) ((x) * (x))
26 #define sqrt(x) sqrt(abs(x))
27 #define y0 y3487465
28 //#define y1 y8687969
29 #define fill(x,y) memset(x,y,sizeof(x))
30 
31 typedef vector<int> vi;
32 typedef long long ll;
33 typedef long double ld;
34 typedef double D;
35 typedef pair<int, int> ii;
36 typedef vector<ii> vii;
37 typedef vector<string> vs;
38 typedef vector<vi> vvi;
39 
40 template<class T> T abs(T x) { re x > 0 ? x : -x; }
41 
42 const int maxn = 115;
43 int n, m, t, k, ans;
44 int x, y;
45 //string s;
46 int p1[maxn], p2[maxn];
47 int a[maxn], b[maxn], c[maxn], d[maxn];
48 int main(){
49     while (~scanf("%d", &n)){
50         int x, y;
51         k = -1;
52         for (int i = 0; i < 4; i++)
53             scanf("%d%d%d%d", &a[i * 2], &a[i * 2 + 1], &b[i * 2], &b[i * 2 + 1]);
54         for (int i = 0; i < 8; i++)
55         for (int j = 0; j < 8; j++){
56             int xi = j, xj = i;
57             if ((j % 2)>(i % 2))xi--, xj++;
58             if ((j % 2) < (i % 2))xi++, xj--;
59             if (a[i] + b[j] <= n&&a[i] >= a[xi]){ k = j / 2, x = a[i], y = b[j]; i = 10, j = 10; break; }
60             if (a[i] + b[j] <= n&&b[j] >= b[xj]){ k = i / 2, x = a[i], y = b[j]; i = 10; j = 10; break; }
61         }
62         if (k == -1){ printf("-1\n"); continue; }
63         printf("%d %d %d\n", k + 1, x, n-x);
64     }
65     return 0;
66 }
View Code


 

posted @ 2013-11-25 03:12  HaibaraAi  阅读(140)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3