## DMOPC '21 Contest 8 P1 - Peanut Planning

View as PDF

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

It is well-known that Anya likes peanuts.

As the head of the city planning department, you have been tasked with planning the construction of a line of peanut shops. The shops will have stocks of peanuts in some order.

Her father however, who you know as Loid Forger, is not a man known for his patience with Anya, and as such will only go to two peanut shops that are side-by-side.

This is fine by Anya as long as she can buy at least peanuts, no matter which two adjacent shops they visit. If the two shops do not have enough stock, she will be quite distraught.

It turns out that of all plans that satisfy Anya's requirement, the lexicographically smallest one is the cheapest. You have been tasked to find the cheapest arrangement to make Anya happy, or sadly report that none exist.

#### Input Specification

The first line will contain space-separated integers and .

The second line will contain space-separated integers, the list of shop stocks.

#### Output Specification

Output the lexicographically smallest array of stocks as specified by the problem. If there is no such array, output -1.

#### Scoring

You will receive 50% of the points for a case if your program outputs an array that satisfies Anya but that is not the cheapest.

#### Sample Input 1

4 8
2 6 10 1

#### Sample Output 1

1 10 2 6

#### Explanation for Sample 1

The adjacent sums are 11 12 8, which are all at least . It can be proven that this is the lexicographically smallest such arrangement.

#### Sample Input 2

4 9
2 6 10 1

#### Sample Output 2

-1

#### Explanation for Sample 2

It can be proven that no arrangement will make Anya happy.

• commented on May 16, 2022, 10:11 p.m.

Can someone look at my submissions and explain why I'm getting TLE for the 1st batch but all AC on the second batch? I tried linear and binary searching so I feel like it's my while loop, but I tested both methods and it works just fine.

• commented on May 16, 2022, 10:23 p.m.

I believe vector erase has linear time complexity. Try to use multiset or map

• commented on April 28, 2022, 4:54 p.m.

You have good taste in anime

• commented on April 26, 2022, 5:01 a.m.

waku waku!