F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Neko's loop

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3593    Accepted Submission(s): 821


Problem Description
Neko has a loop of size $n$.
The loop has a happy value $a_{i}$ on the $i-th(0 \leq i \leq n - 1)$ grid.
Neko likes to jump on the loop.She can start at anywhere. If she stands at $i-th$ grid, she will get $a_{i}$ happy value, and she can spend one unit energy to go to $((i + k) \bmod n)-th$ grid. If she has already visited this grid, she can get happy value again. Neko can choose jump to next grid if she has energy or end at anywhere.
Neko has $m$ unit energies and she wants to achieve at least $s$ happy value.
How much happy value does she need at least before she jumps so that she can get at least $s$ happy value? Please note that the happy value which neko has is a non-negative number initially, but it can become negative number when jumping.
 

Input
The first line contains only one integer $T ( T \leq 50)$, which indicates the number of test cases.
For each test case, the first line contains four integers $n, s, m, k(1 \leq n \leq 10^4, 1 \leq s \leq 10^{18}, 1 \leq m \leq 10^9, 1 \leq k \leq n)$.
The next line contains $n$ integers, the $i-th$ integer is $a_{i-1}(-10^9 \leq a_{i-1} \leq 10^9)$
 

Output
For each test case, output one line "Case #x: y", where x is the case number (starting from 1) and y is the answer.
 

Sample Input
2 3 10 5 2 3 2 1 5 20 6 3 2 3 2 1 5
 

Sample Output
Case #1: 0 Case #2: 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-18 18:22:35, Gzip enabled