Orig Description
B: Yamanote-line Game
Trivia
Yamanote-line is convenient. That's because you can ride it as many times as you want as long as you pay 130 yen. However, if you ride with a ticket, you have to be careful about the valid time of the ticket. It seems safe if you use an IC card. Taking advantage of this characteristic of the Yamanote-line, there are people who indulge in a nap while being rocked by the train in the Tokyo suburbs. By the way, the author of this problem has never done that. It is rare to be caught by a station staff, but it seems troublesome if you are caught, so it is not recommended.
Problem Statement
Let's play a game using the characteristic of the Yamanote-line. Here, for generalization, let's consider a Yamanote-line modoki where N stations numbered from 1 to N are arranged in a circle in the order of 1, 2, ..., N, and you can ride on the line for d yen to any station from any station. The game follows the following rules:
Select any station as the starting point and ride on the Yamanote-line modoki for d yen.
After that, get off at any station and ride again.
The game ends when you get off at the starting station.
You can earn p_i yen if you get off at station i.
However, you cannot earn rewards again at a station where you have received rewards once.
Also, it costs d yen to ride the Yamanote-line modoki again after getting off.
Now, how much can you earn at most? Please try to challenge.
Input Format
N d
p_1 p_2 … p_N
All inputs are integers.
In the first line, the number of stations N and the fare d to ride the Yamanote-line modoki are given separated by a space.
In the second line, the reward that can be obtained at each station is given separated by spaces, and the i-th value p_i represents the reward at station i.
Constraints
3 ≤ N ≤ 1,000
1 ≤ d ≤ 1,000
1 ≤ p_i ≤ 1,000 (1 ≤ i ≤ N)
Output Format
Output the maximum amount of money you can earn in the game on one line. If you cannot earn more than 1 yen, output "kusoge" on one line. The end of the output must be a newline character and must not contain any unnecessary characters.
Sample Input 1
5 130
130 170 100 120 140
Sample Output 1
50
Sample Input 2
3 100
100 90 65
Sample Output 2
kusoge
Sample Input 3
6 210
300 270 400 330 250 370
Sample Output 3
660
Sample Input 4
4 540
100 460 320 280
Sample Output 4
kusoge
Extracted Specification
An integer N (3 ≤ N ≤ 1,000), representing some quantity or size.
An integer d (1 ≤ d ≤ 1,000), representing some cost or value.
A list of integers p of size N, where each integer is between 1 and 1,000.
### Example Input:
```
5 130
130 170 100 120 140
```
### Function Signature:
Write a function f(N, d, p) that takes in the input.
```python
def f(N: int, d: int, p: List[int]):
'''
N: an integer
d: an integer
p: a list of integers
'''
```
Test Case Generator
Sure, here is a test case generator for the Yamanote-line Game problem statement:
```python
import random
def tcgen():
# Generate N and d
N = random.randint(3, 1000)
d = random.randint(1, 1000)
# Generate rewards for each station
p = [random.randint(1, 1000) for _ in range(N)]
return N, d, p
# Example usage:
if __name__ == "__main__":
N, d, p = tcgen()
print(N, d)
print(" ".join(map(str, p)))
```
### Explanation
1. **N** is generated randomly between 3 and 1000, as per the problem constraints.
2. **d** is generated randomly between 1 and 1000.
3. The list **p** contains N integers, each representing the reward at a station, randomly chosen between 1 and 1000.
### Sample Output
Running this generator might yield an output like:
```
8 457
300 500 120 450 700 330 250 370
```
This output corresponds to:
- 8 stations (N = 8)
- Fare d = 457 yen
- Rewards at the stations: `[300, 500, 120, 450, 700, 330, 250, 370]`
You can then use these generated values as input for testing your solution to the problem.
Extract Arguments
def extract_arguments(fh):
N, d = map(int, fh.readline().strip().split())
p = list(map(int, fh.readline().strip().split()))
return N, d, p