Three arrays

1.9

10 votes
Backtracking, Basic Programming, Recursion
Problem

You are given three arrays a1n,b1n,c1n and two numbers M and K. Find a lexicographically minimum {x,y,z} such that there are exactly K indices i(1in) where xai+ybiciz=Mf for some integer f. Also, you are given ranges of x, y, and z-- l1..3,r1..3((l1xr1,l2yr2,l3zr3). Here, a triplet of integers {x1,y1,z1} is considered to be lexicographically smaller than a triplet {x2,y2,z2} if sequence [x1,y1,z1] is lexicographically smaller than sequence [x2,y2,z2]. A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.

Input format

  • The first line contains one three integers n,m,K(1n10000,0Kn,1M15).
  • The next n lines contain three integers ai,bi,ci(1ai,bi,ci109).
  • The next three lines contain two integers li,ri(1liri109).

Output format

If an answer does not exist, print -1. Otherwise, print desirable {x,y,z}.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Since, K=n=4, the above condition must hold for all indices. i=1)35+3631=30i=2)32+3639=3i=3)311+3536=30i=4)31+3131=3. As we can see, it is correct.

Editor Image

?