Jian-Jia is planning his next holiday in Taiwan. During his holiday, Jian-Jia moves from city to city and visits attractions in the cities.
There are
Each city contains some number of attractions. Jian-Jia has
Example
Suppose Jian-Jia has 7 days of holiday, there are 5 cities (listed in the table below), and he starts from city 2. On the first day Jian-Jia visits the 20 attractions in city 2. On the second day Jian-Jia moves from city 2 to city 3, and on the third day visits the 30 attractions in city 3. Jian-Jia then spends the next three days moving from city 3 to city 0, and visits the 10 attractions in city 0 on the seventh day. The total number of attractions Jian-Jia visits is
city | number of attractions |
---|---|
0 | 10 |
1 | 2 |
2 | 20 |
3 | 30 |
4 | 1 |
day | action |
---|---|
1 | visit the attractions in city 2 |
2 | move from city 2 to city 3 |
3 | visit the attractions in city 3 |
4 | move from city 3 to city 2 |
5 | move from city 2 to city 1 |
6 | move from city 1 to city 0 |
7 | visit the attractions in city 0 |
Task
Please implement a function findMaxAttraction
that computes the maximum number of attractions Jian-Jia can visit.
findMaxAttraction(n, start, d, attraction)
n
: the number of cities.start
: the index of the starting city.d
: the number of days.attraction
: array of length ;attraction[i]
is the number of attractions in city , for .- The function should return the maximum number of attractions Jian-Jia can visit.
Subtasks
In all subtasks
Additional constraints:
subtask | points | maximum number of attractions in a city | starting city | |
---|---|---|---|---|
1 | 7 | no constraints | ||
2 | 23 | city 0 | ||
3 | 17 | no constraints | ||
4 | 53 | no constraints |
Implementation details
Your submission should implement the subprogram described above using the following signatures.
Note that the result may be large, and the return type of findMaxAttraction
is a 64-bit integer.
C/C++ program
long long int findMaxAttraction(int n, int start, int d, int attraction[]);
Pascal program
function findMaxAttraction(n, start, d : longint; attraction : array of longint): int64;
Comments