Help

Bitland has N cities connected by one common highway. East of the first
the city has a Bitzon warehouse. Distance from Bitzon warehouse to first city
is m1 time units, from the first to the second city - m2 time units, and so on as
shown in the illustration:
A pile of parcels is brought to the warehouse every day for the courier to take out. For everyone
the address (city number) and the time when the parcel is to be delivered.
Parcels may be delivered by courier earlier than planned, but necessarily not later than specified
time.
The courier leaves the warehouse in the morning (we will consider this moment at time 0) and travels from one city
delivering parcels to another.
In this task, we will assume that the delivery of the parcel does not take time, only driving from
from one city to another.
Task. Known list of parcels to be delivered by the courier. Find:
1. Will the courier be able to deliver all parcels without delay.
2. In as little time as possible, the courier will be able to deliver all parcels and return to the warehouse.
Initial data. The first line contains the number of cities N. The second line contains
N integers - distances m1, m2,. . . , mN. The third line contains the number of parcels K.
Finally, follow the K lines describing all the parcels. Each of these lines is presented after
two integers: city number ai (1 ≤ ai ≤ N) where the parcel is to be delivered,
and the latest possible delivery time ti
.
Assume that the courier leaves the warehouse at time 0. Can be delivered to the same city
more than one parcel. The courier can deliver the parcels in any order (but without delay).
Results. Output a single integer in the least amount of time possible
all parcels and return to the warehouse. If at least one parcel cannot be delivered on time,
output −1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>

using namespace std;

int main()
{
    int N; //how many cities
    int K; //how many parcels
    
    cin >> N;

    int m[N]; //distance between cities

    for(int i = 0; i < N; i++)
    {
        cin >> m[i];
    }
//--------------------------------
    cin >> K;

    int a[K]; 
    int t[K]; 

    for(int i = 0; i < K; i++)
    {
        if(i == K)
        {
            
        }
        cin >> a[1] >> t[i];
    }
//---------------------------------
 


    for(int i = 0; i < K; i++)
    {
        for(int j = 0; j < i; j++)
        {
            if(a[i] == a[j])
            {

            }

            if(a[i] != a[j])
            {
                for(int k = 0; k < j; k++)
                {

                }
            }
        }
    }

    return 0;
}

/*
6
30 30 40 20 10 70
3
2 70
5 130
3 180
*/
// the result should be 260 
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;

int main()
{
    // read the number of cities into a variable

    // read the city distances into an array
    // (hint: declare an array and use a for-loop to fill it)

    // read the number of parcels

    // create variables to represent data of interest
    bool canDeliverOnTime = true;  // A flag to set based on whether a parcel delivery
                                   // address distance exceeds its deadline
    int farthestParcelAddr = 0;    // Address that's farthest from warehouse, used
                                   // to determine the shortest delivery time possible

    // for each parcel...
    for (int i = 0; i < /*number of parcels*/; i++)
    {
        // read in the parcel address and parcel deadline

        // if this parcel address is the farthest one you've seen,
        // stick the address in the farthestParcelAddr variable

        // find out how far away this parcel must be delivered
        // (hint: loop over the city distances array and add up the distances
        //        as you go until you get to the right address)

        // determine if it is impossible to deliver this parcel on time
        if (/*parcel deadline is shorter than the delivery distance*/)
        {
            // we have a parcel that can't deliver on time!
            canDeliverOnTime = false; // set flag to use later
            break;  // break out of for loop - no need to examine more parcels
        }
    } // done examining parcels

    if (canDeliverOnTime)
    {
        // calculate total distance to farthest parcel delivery
        // (hint: use the farthestParcelAddr to determine how many
        //        city distances to add together to get the distance
        //        to the farthest delivery)

        // the shortest delivery time is the time it takes
        // to get to the farthest address and back
        cout << (/*distance to farthest*/ * 2);
    }
    else
    {
        // print appropriate output for not being able to deliver
        cout << (-1);
    }
}
Topic archived. No new replies allowed.