Codeforces round #159 (Div. 2) d sum

Source: Internet
Author: User
Codeforces round #159 (Div. 2) d sum D. sumtime limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Vasya has found a piece of paper with an array written on it. The array consistsNIntegersA1, bytes,A2, middle..., middle ,...,AN.
Vasya noticed that the following condition holds for the ArrayAILimit ≤ limitAILimit + limit 1 limit ≤ limit 2 ·AIFor
Any positive integerI(ILatency <latencyN).

Vasya wants to add either a "+" or a "-" before each number
Of array. Thus, Vasya will get an expression consistingNSummands. The value of the resulting expression
Is the sum of all its elements. The task is to add signs "+" and "-"
Before each number so that the value of expressionSMeets the limits 0 limit ≤ limitSLimit ≤ limitA1.
Print a sequence of signs "+" and "-", satisfying the given
Limits. it is guaranteed that the solution for the problem exists.

Input

The first line contains integerN(1 digit ≤ DigitNLimit ≤ limit 105)
-The size of the array. The second line contains space-separated IntegersA1, bytes,A2, middle..., middle ,...,AN(0 bytes ≤ bytesAILimit ≤ limit 109)
-The original array.

It is guaranteed that the conditionAILimit ≤ limitAILimit + limit 1 limit ≤ limit 2 ·AIFulfills
For any positive integerI(ILatency <latencyN).

Output

In a single line print the sequenceNCharacters "+"
And "-", whereI-Th
Character is the sign that is placed in front of numberAI.
The value of the resulting expressionSMust fit into the limits 0 limit ≤ thresholdSLimit ≤ limitA1.
If there are multiple solutions, you are allowed to print any of them.

Sample test (s) Input
41 2 3 5
Output
+++-
Input
33 3 5
Output
++-
  A group of incremental numbers A1, A2, a3 ..... an (a (I-1) <= a (I) <= 2 * a (I-1 )), add the '+' or '-' operator between the numbers to calculate a sum, which requires 0 <= sum <= A1; (sum starts to 0 ;) output a set of conforming operator strings (the answer may not be unique, and one of them can be output and must have a solution );       This question won't be done at the beginning... Think too complicated .... Only by looking at other people's code can we know that pure mathematical derivation is made.   ~~~~~ I am ashamed of my lack of experience .....     Derivation:
Set Data A1, A2, a3 ...... A (n-2), a (n-1), a (n); because the data satisfies a (I-1) <= a (I) <= 2 * a (I-1); therefore, a (n) is the largest, so it is reduced from a (n). Because a (n-1) <= a (n) <= 2 * a (n-1); therefore, K is set to a (n)-a (n-1 ); 0 <= k <= a (n-1); because a (n-2) <= a (n-1) <= 2 * a (n-2 ); and k> 0 0 <= k <= 2 * a (n-2); So k = k-a (n-2); so-a (n-2) <= k <= a (n-2); so 0 <= ABS (k) <= a (n-2); so when n> 2, ABS (k) it must be between 0 and a (n-2). When k is <0,-K is greater than 0, and n = 2, 1 is also true. So the practice is very simple. Code:
 
# Include <stdio. h >__ int64 num [100100]; char ch [100100]; int main () {int N, I, J, K; scanf ("% d", & N ); for (I = 0; I <n; I ++) scanf ("% i64d", & num [I]); k = num [n-1]; // K is sum; ch [n-1] = '+'; for (I = N-2; I> = 0; I --) {If (k> = 0) {ch [I] = '-'; k-= num [I];} else {ch [I] = '+ '; K + = num [I] ;}} if (k <0) // when K is less than 0, all the conformances must be the opposite. k is rounded up to {for (I = 0; I <n; I ++) printf ("% C", CH [I] = '+ '? '-': '+'); Printf ("\ n");} elseprintf ("% s \ n", CH );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.