#QHD0000067. Đồng tiền hai giá trị (e-Coins)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đồng tiền hai giá trị (e-Coins)
e-Coins
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Every electronic coin has two nonnegative components : a conventional value and a technological value. Each coin type is available in unlimited quantities. If the chosen coins contribute total values and , the e-modulus of the whole selection equals . Add the two components separately before computing the square root. You must not sum individual coin lengths.
Given available types and a target integer e-modulus , find the minimum number of coins whose total components satisfy . If impossible, print not possible. The zero vector may be ignored in an optimal solution. Because components are nonnegative, a coin with either component larger than cannot be used. Both axis-aligned vectors and vectors with two nonzero components are permitted.
Input
The first line contains . Each of the next lines contains the two nonnegative components of a coin type.
Output
Print the minimum number of coins, or exactly not possible if the target e-modulus cannot be obtained.
Subtasks
- Subtask 1 (20 points): ; ; each is a nonnegative integer up to ; unlimited coins per type.
- Subtask 2 (30 points): ; ; each is a nonnegative integer up to ; unlimited coins per type.
- Subtask 3 (50 points): ; ; each is a nonnegative integer up to ; unlimited coins per type.
Examples
Input
3 5
3 0
0 4
5 5
Output
2
Explanation
Select and : totals satisfy . No single available coin has e-modulus , hence two coins are optimal.