#CCBCHBON0000050. Thoát hai mức khi tìm cặp đầu tiên (First Pair of Squares: Exit Both Loops)
Thoát hai mức khi tìm cặp đầu tiên (First Pair of Squares: Exit Both Loops)
First Pair of Squares: Exit Both Loops
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given n,T, enumerate pairs 1<=i<j<=n lexicographically (i increasing, then j increasing). Print the first pair satisfying ii+jj=T, or -1 -1 if none. An inner-loop break alone does not stop the outer loop, so carry the found flag to it.
Input
One line contains n,T; 2<=n<=100 and 2<=T<=20000.
Output
Print i and j separated by one space, or -1 -1.
Subtasks
-
Subtask 1 (20%): ; .
-
Subtask 2 (30%): ; .
-
Subtask 3 (50%): ; .
Examples
Example 1
Input:
5 25
Output:
3 4
Explanation:
Loop i then j in ascending order; report the first qualifying pair. Exact input: "5 25\n"; exact output: "3 4\n".
Example 2
Input:
3 2
Output:
-1 -1
Explanation:
Loop i then j in ascending order; report the first qualifying pair. Exact input: "3 2\n"; exact output: "-1 -1\n".
Example 3
Input:
5 100
Output:
-1 -1
Explanation:
Loop i then j in ascending order; report the first qualifying pair. Exact input: "5 100\n"; exact output: "-1 -1\n".
Example 4
Input:
5 5
Output:
1 2
Explanation:
Loop i then j in ascending order; report the first qualifying pair. Exact input: "5 5\n"; exact output: "1 2\n".