GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 21 August 2022

[Solution] Pizza Delivery Solution Round E 2022 | Kick Start 2022



Problem

Ada delivers pizzas in a city consisting of a grid of N horizontal and N vertical streets, heading from North to South and from West to East, respectively, and numbered from 1 to N. The top left street crossing of the grid is (1,1).

Today, Ada has to deliver P pizzas, one for each of P customers. Each customer lives at a different street crossing; the k-th customer lives at street crossing (Xk,Yk) and will pay Ada Ck coins after the pizza is delivered to their location.

Ada starts at her pizza restaurant at (Ar,Ac) with 0 coins and carrying P pizzas. Her goal is to deliver all of the pizzas within M minutes. She is free to take any path she likes around the city and finish deliveries anywhere, as long as she manages to drop off all P pizzas to their respective customers within M minutes. It takes one minute to walk between two adjacent street crossings, and takes no additional time to drop off a pizza at a customer's location. There are some additional rules and constraints to note:

  • Ada is not allowed to go outside the grid.
  • No customer lives at the same street crossing as the pizza restaurant Ada starts her trip.
  • At any point in time Ada can choose to stay in her current location and not move.
  • Ada can also choose not to deliver a pizza when at a customer's location.

Formally, if Ada is currently at street crossing (i,j), where i is i-th row from the top, and j is j-th column from the left, she can decide to do any of the following as long as she does not go outside the grid:

  • Go north, she reaches street crossing (i1,j).
  • Go east, she reaches street crossing (i,j+1).
  • Go west, she reaches street crossing (i,j1).
  • Go south, she reaches street crossing (i+1,j).
  • Stay at street crossing (i,j).

City with 3 horizontal and vertical streets

The city has a unique toll system in place for using the streets. There is a toll for using each street and the toll depends on Ada's current number of coins and the direction in which she is travelling to. The toll function is defined for every cardinal direction (North, East, West, South) separately. The toll function Fd for d{North,East,West,South} returns the amount of coins Ada will have after moving in the direction d and is defined as follows:

Fd = c OPd Kd

where c is the current number of coins that Ada has and OPd is an operator and Kd is a fixed positive integer. The allowed operators are:

For example, we can have FNorth = c + 3FEast = c * 4FWest = c - 4FSouth = c / 2. That means that if Ada moves North one street then she will have 3 more coins; if Ada moves East then Ada's coins will quadruple; if Ada moves West then she loses 4 coins; and if Ada moves South then her coins are halved.

All divisions are integer divisions and are computed by using floor function. For example, 14=14=1. Notice that Ada is allowed to have a negative number of coins. Note that the tolls might actually give Ada coins.

Find out if Ada can deliver all the P pizzas in M minutes and, if so, the maximum number of coins Ada could have after M minutes.

Input

The first line of the input gives the number of test cases, TT test cases follow.

The first line of each test case contains NPMArAc denoting the grid size, the number of pizzas to deliver, the minutes in which all pizzas should be delivered, and the coordinates of the street crossing at which Ada starts respectively.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

The next four lines denote the toll functions for North, East, West, South respectively. Each of these lines contains OPd, denoting the operator (one of +-*/), and Kd, the positive integer used in toll function.

The following P lines describe the customers. Each of these lines consists of three integers XkYkCk denoting the row number of the k-th customer from the top of the grid, the column number of the k-th customer from the left of the grid, and the amount of coins they pay on delivery, respectively.

Output

For each test case, output one line containing Case #xy, where x is the test case number (starting from 1) and y is IMPOSSIBLE if all pizzas cannot be delivered within M minutes; otherwise, the output should be the maximum number of coins Ada can have after M minutes (which could be negative).

Limits

Time limit: 20 seconds.
Memory limit: 1 GB.
1T100.
1N10.
1M20.
1Ar,AcN.
1Xk,YkN, for all k.
1Ck4, for all k.
1Kd4, for all d.
OPd is one of (+-*/), for all d.
It is guaranteed that no customer lives at the same street crossing as the pizza restaurant Ada starts her trip, i.e. (Xk,Yk)(Ar,Ac), for all 1kP.
It is guaranteed that every customer lives at a different street crossing, i.e. (Xk,Yk)(Xl,Yl), for all 1k,lP and kl.

Test Set 1

P=0.

Test Set 2

0P10.

Sample

Note: there are additional samples that are not run on submissions down below.

In Additional Sample Case #1, Ada started at street crossing (1,3) with 0 coins. Ada can receive maximum coins by following the steps below:

  • Go west to (1,2). Using the toll function for moving west Fwest = c * 1, Ada now has 01=0 coins.
  • Do not deliver the pizza at (1,2) yet, and go south to (2,2). Using the toll function for moving south FSouth = c / 4, Ada now has 0/4=0 coins.
  • Go north to (1,2). Using the toll function for moving north FNorth = c + 4, Ada now has 0+4=4 coins.
  • Deliver the pizza at (1,2). Ada receives 4 additional coins for delivering the pizza. Ada has a total of 8 coins in the end.

In Additional Sample Case #2, Ada cannot deliver two pizzas in one minute, so the output is IMPOSSIBLE.

In Additional Sample Case #3, Ada started at street crossing (1,3) with 0 coins. Ada can receive maximum coins by following the steps below:

  • Go west to (1,2). Using the toll function for moving west FWest = c - 3, Ada now has 03=3 coins.
  • Go south to (2,2). Using the toll function for moving south FSouth = c / 4, Ada now has 3/4=34=1 coins.
  • Deliver the pizza at (2,2). Ada receives 2 additional coins for delivering the pizza. Ada has a total of 1 coins in the end.

No comments:

Post a Comment