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
Canonicalized Input Description:
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.
def f(N: int, d: int, p: List[int]):
'''
N: an integer
d: an integer
p: a list of integers
'''
Test Case Generator
Certainly! Here is a Python function to generate test cases for the "Yamanote-line Game" problem:
```python
import random
def tcgen():
# N is the number of stations
N = random.randint(3, 1000)
# d is the fare to ride the Yamanote-line modoki
d = random.randint(1, 1000)
# p is the list of rewards at each station
p = [random.randint(1, 1000) for _ in range(N)]
return N, d, p
# Generate a test case and print it in the required format
N, d, p = tcgen()
print(N, d)
print(" ".join(map(str, p)))
```
This function generates random values for the number of stations \(N\), the fare \(d\), and the rewards \(p[i]\) for each station within the provided constraints. It then prints the test case in the required format.
You can use this function to generate various test cases for the "Yamanote-line Game" problem. Here's how it works:
1. `N` is randomly chosen between 3 and 1000.
2. `d` is randomly chosen between 1 and 1000.
3. `p` is a list of \(N\) integers, each randomly chosen between 1 and 1000.
You can run this function multiple times to generate different test cases for testing your solution.
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