#QHD0000057. Sổ thu chi (Account Book)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sổ thu chi (Account Book)
Account Book
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A book page lists positive transaction amounts in chronological order. The sign of each transaction has been erased: it could be an income (+) or an expense (-). However, the exact signed net cash flow is known; it may be positive, negative, or zero.
An assignment is valid when every transaction receives one sign and the signed sum equals . Determine what can be concluded about each transaction across all valid assignments, not just across one arbitrary solution.
For transaction , print + if it is income in every valid assignment, - if it is expense in every valid assignment, and ? if both possibilities occur among valid assignments. If no assignment exists at all, print * instead of the sign string. Equal transaction amounts at different positions remain distinct transactions.
Input
The first line contains and . Each of the next lines contains one positive transaction amount . There is no terminating 0 0 line.
Output
If there is no valid sign assignment, print *. Otherwise print exactly characters, the -th being +, -, or ? according to the definition, without spaces.
Subtasks
-
Subtask 1 (20 points): , , for every .
-
Subtask 2 (30 points): , , for every .
-
Subtask 3 (50 points): , , for every .
Examples
Input
5 7
1
2
3
4
5
Output
?+??+
Explanation
For amounts and required sum , the second and fifth transactions are positive in every valid assignment. The first, third, and fourth transactions can have either sign in different valid assignments. The output is ?+??+. A target of would be impossible because the sum of all positive amounts is only , and the output would then be *.