Shopee Programming Contest
Shopee Programming Contest
02 : 40 : 06
HRS MIN SEC
Mar 20, 2021, 02:00 PM SGT - Mar 20, 2021, 05:00 PM SGT
Problems / Sho ee
Sho ee
Max. score: 20
It has been a year since Noel joined Shopee. Like every ordinary day, before starting daily work, Noel will go to the pantry and make a cup of
co ee for himself.
A box of length is placed next to the co ee machine in the pantry, and co ee beans of di erent avors are placed in a row. Noel has his
own taste preference value for each type of co ee bean. Noel has a habit of his own, that is, every time he makes co ee, he will select
co ee beans in consecutive boxes (assuming that each avor of co ee beans is unlimited supply) and put them into the co ee machine to get
a cup of mixed co ee whose taste preference value will be the average value of the chosen avors.
A cup of mixed co ee will be called Sho ee if its taste preference value not less than , Sho ee can quickly wake Noel up.
Noel hopes that every day he can drink a cup of Sho ee and keep himself in a good working status. Please help him calculate how many types
of Sho ee can be in total.
Input Format
The rst line are two positive integers ( ) and ( ) splitted by space, representing the number of co ee bean
avors, and Noel’s expectation for the co ee.
The second line contains positive integers ( ) splitted by space, representing Noel’s preference value for each type of co ee
bean.
Output Format
For each test case, please output an answer in one line representing the number of Sho ee can be in total.
SAMPLE INPUT
3 3
1 3 4
SAMPLE OUTPUT
Explanation
For the rst test case, there are totally 6 di erent consecutive sequences: , and their average values are
.
Among these, there will be 3 numbers greater than or equal to , so the answer will be 3. ?
Memory Limit: 64 MB
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin,
Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1,
CODE EDITOR
1:1 vscode
Tip: You can submit any number of times you want. Your best submission is considered for computing total score.
Support: For any queries or issues, write to techsg@shopee.com.
?
Shopee Programming Contest Shopee Singapore
02 : 39 : 24
HRS MIN SEC
Mar 20, 2021, 02:00 PM SGT - Mar 20, 2021, 05:00 PM SGT
Shopee Farm
Max. score: 10
Shopee Farm is a popular game in Shopee App. In Shopee Farm, you can plant some plants. One of the game developers has an idea to create
a new sub game in Shopee Farm. In the sub game, you are given a park and the park has 1 dimensional shape and it consists of di erent
cells. In each cell you must plant exactly 1 tree. Each day, the tree can yield a bene cial fruit / poisonous fruit / neither bene cial nor poisonous
fruit. The bene cial fruit means that you will get a positive number of health. The poisonous fruit gives you a negative number of health.
Otherwise, you will get 0 health.
Then you are given a character that will start at the left side of the one dimensional park. You are given days to play the game. Each day, the
number of health in each fruit produced by a tree might change. In one day the character can do one of these actions:
Note: On one day, the fruit in a cell can be gotten at most once.
Input
There will be number of test cases. On each test case, there will be a line with 2 integers, and
Then lines follow up, with each line containing integers, ,
which means the health of the fruit on day at cell .
Output
The output must consist of number of integers, indicating the maximum amount of health that the character can get.
SAMPLE INPUT
3
1 5
-9 -8 1 2 3
2 3
1 4 -5
-1 -9 100
2 3
1 4 -5
-1 -1 100
SAMPLE OUTPUT
0
100
103 ?
Explanation
1. For the rst example, the character can decide to not cross the park at all, hence the total health that the character gets is 0.
2. For the second example,
1. On the rst day, the character goes from the left, then completely crossing the park, then he rests at the right side of the park, and
the total number of health is: 1 + 4 + (-5) = 0.
2. On the second day, the character goes from the right side of the park, only to the rst cell from the right, then go back to the right
side of the park, and the total number of health the character gets from the second day is 100.
3. Hence, the total health that the character gets from 2 days is 0 + 100 = 100.
3. For the third example,
1. On the rst day, the character goes from the left, but only getting the health from the rst 2 cells, then the character goes back to
the left side of the park, and the total number of health is: 1 + 4 = 5.
2. On the second day, the character goes from the left side of the park, and goes completely crossing the park, gaining total health of:
(-1) + (-1) + 100 = 98 for the second day.
3. Hence, the total health that the character gets from 2 days is 5 + 98 = 103.
Memory Limit: 64 MB
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin,
Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1,
CODE EDITOR
1:1 vscode
Tip: You can submit any number of times you want. Your best submission is considered for computing total score.
Support: For any queries or issues, write to techsg@shopee.com.
?
Shopee Programming Contest Shopee Singapore
02 : 39 : 02
HRS MIN SEC
Mar 20, 2021, 02:00 PM SGT - Mar 20, 2021, 05:00 PM SGT
Problems / Divider
Divider
Max. score: 20
Shopee has software engineers. Shopee accommodates them by arranging tables on a 1D plane. However, many people raise concerns
that the work environment is too noisy. To mitigate this issue, Shopee decides to group the engineers into groups. A group is a non-
overlapping segment of contiguous engineers. Shopee will then put dividers between the groups.
Let:
be the noise value of a group consisting of the l-th engineer up to the r-th engineer.
Shopee wants to minimize the total noise value. Please help Shopee to nd the minimum total noise value possible.
Input
The rst line of input contains 2 integers: , representing the number of engineers and the
number of groups respectively. The next line contains integers: representing the noise factor of the i-th engineer.
Output
Output in a line an integer representing the minimum total noise value possible.
SAMPLE INPUT
4 2
1 3 2 4
SAMPLE OUTPUT
20
Explanation
1. 1 | 3 2 4
Noise = (1 * 1) + (9 * 3) = 28
2. 1 3 | 2 4 ?
Noise = (4 * 2) + (6 * 2) = 20
3. 1 3 2 | 4
Noise = (6 * 3) + (4 * 1) = 22
We can see that from all the possibilities, 20 is the minimum total noise value.
Memory Limit: 64 MB
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin,
Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1,
Swift, TypeScript, Visual Basic
CODE EDITOR
1:1 vscode
Tip: You can submit any number of times you want. Your best submission is considered for computing total score.
Support: For any queries or issues, write to techsg@shopee.com.
?
Shopee Programming Contest Shopee Singapore
02 : 38 : 43
HRS MIN SEC
Mar 20, 2021, 02:00 PM SGT - Mar 20, 2021, 05:00 PM SGT
Order Delivery
Max. score: 20
In the parallel universe, where there are 13 months, Shopee has a 13.13 campaign. During this 13.13 campaign, Shopee gives free shipping
delivery vouchers to all users who buy the item . Shopee has warehouses to store the item , and each warehouse has number of
item . Each warehouse is located in a city and all cities have at most one warehouse. To serve the customers, each warehouse has its own
courier delivery. The cost of the delivery from the warehouse is dollar per kilometer. Interestingly, in this parallel universe, the distance
between neighboring cities is exactly one kilometer. The cities can be represented as a graph, where a node represents the city and an edge
represents the road between cities, and all the cities are connected. Warehouse is located at city .
During the 13.13 campaign, people are very excited to buy this item because of the free shipping discounts. As a result, there are orders
created. The -th order contains number of item , and it needs to be delivered to city . To serve all the customers, multiple
warehouses can be used to serve a single order. So, one order can be served by multiple warehouses.
Because of the free shipping discounts, Shopee needs to pay the delivery fee of all the orders. Your task is to help Shopee to minimize the
delivery fee in this 13.13 campaign.
Input Format
The rst line contains three integers , , and representing the number of cities,
warehouses, and roads in this parallel universe. The next lines contain 2 integers and which indicates
that there is a road between city and . The next line contains 3 integers , , and
which represents the number of item in warehouse and the delivery fee of warehouse
per kilometer and the location of warehouse . The next line contains an integer which represents the number of
orders. Each of the next lines contain two integers and which represent
the number of item ordered in order- and the city of order .
Output Format
Output a single integer contains the total delivery cost of all orders. It is guaranteed that Shopee can serve all the orders.
SAMPLE INPUT
8 3 11
1 2
1 3
2 3
3 4
4 5
5 6
5 7
5 8
4 6
3 7
7 8
12 5 1
11 10 6 ?
1 6 7
3
3 4
4 4
7 5
SAMPLE OUTPUT
136
Memory Limit: 64 MB
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin,
Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1,
CODE EDITOR
1:1 vscode
Tip: You can submit any number of times you want. Your best submission is considered for computing total score.
Support: For any queries or issues, write to techsg@shopee.com.
?
Shopee Programming Contest Shopee Singapore
02 : 38 : 33
HRS MIN SEC
Mar 20, 2021, 02:00 PM SGT - Mar 20, 2021, 05:00 PM SGT
Shopee Planet
Max. score: 30
Shopee Planet is a new game in Shopee app. In this game, you are living on a planet which looks like a giant soccer ball. Similar to a soccer
ball, there are 12 pentagon faces and 20 hexagon faces which form a "Truncated Icosahedron" as follows:
On each pentagon face, there is a tree. Each tree will produce some Shopee coins after each day. After seven days, if the coins on a face are
not collected, the tree on that face will stop producing coins (until the coins are collected). Due to the climate di erence between pentagon
faces and hexagon faces, trees are only available on pentagon faces.
Let's " atten" the soccer ball and number the pentagon faces as follows:
There are days in total. On the rst day (day 0), you are standing on the hexagon face surrounded by face 1, 2, and 3 (the center face in
Figure 2). Each day, you have to move to an adjacent face (you are not allowed to stay at the current face), collect all the Shopee coins on that
face (if available). The number of coins you can collect is determined by this rule: ?
If you are standing on a hexagon face, there are no Shopee coins to collect.
Otherwise, let be the id of the pentagon face that you are standing on,
If this is the rst time you visit this face, the number of coins is
Otherwise, let be the index of the most recent day that you visited this face, let be the index of the current day, the number
of coins is
Input
Output
Output the maximum number of Shopee coins that you can collect.
Note
To make sure that you have read the problem statement correctly, here are some facts that you can use to verify your understanding:
SAMPLE INPUT
1
100 200 300 400 500 600 700
101 201 301 401 501 601 701
102 202 302 402 502 602 702
103 203 303 403 503 603 703
104 204 304 404 504 604 704
105 205 305 405 505 605 705
106 206 306 406 506 606 706
107 207 307 407 507 607 707
108 208 308 408 508 608 708
109 209 309 409 509 609 709
110 210 310 410 510 610 710
111 211 311 411 511 611 711
SAMPLE OUTPUT
702
Explanation
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin,
Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1,
Swift, TypeScript, Visual Basic
?
CODE EDITOR
Save Python (python 2.7.6)
1 '''
2 # Sample code to perform I/O:
3
4 name = raw_input() # Reading input from STDIN
5 print 'Hi, %s.' % name # Writing output to STDOUT
6
7 # Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
8 '''
9
10 # Write your code here
11
1:1 vscode
Tip: You can submit any number of times you want. Your best submission is considered for computing total score.
Support: For any queries or issues, write to techsg@shopee.com.