package current ;
import io.Reader ;
import io.OutputWriter ;
public class ManageYourEnergy {
long e,r;
int n;
public void solve
( int testNumber,
Reader in, OutputWriter out
) { e = in.nextInt ( ) ;
r = in.nextInt ( ) ;
n = in.nextInt ( ) ;
int [ ] v = in.nextIntArray ( n) ;
out.println ( "Case #" + testNumber + ": " + solve( v, 0 , n, e, 0 ) ) ;
}
private long solve( int [ ] v, int from, int to, long startE, long toE) {
if ( from == to)
return 0 ;
int index = from;
for ( int i = from; i < to; ++ i) {
if ( v[ i] > v[ index] )
index = i;
}
long startHere
= Math .
min ( e, startE
+ ( index
- from
) * r
) ; long endHere
= Math .
max ( 0 , toE
- ( to
- index
- 1 ) * r
) ;
return solve
( v, from, index, startE,
Math .
max ( startHere
- r,
0 ) ) + ( startHere
- endHere
) * 1L
* v
[ index
] + solve
( v, index
+ 1 , to,
Math .
min ( e, r
+ endHere
) , toE
) ;
}
}
cGFja2FnZSBjdXJyZW50OwoKaW1wb3J0IGlvLlJlYWRlcjsKaW1wb3J0IGlvLk91dHB1dFdyaXRlcjsKCnB1YmxpYyBjbGFzcyBNYW5hZ2VZb3VyRW5lcmd5IHsKICAgIGxvbmcgZSxyOwogICAgaW50IG47CiAgICBwdWJsaWMgdm9pZCBzb2x2ZShpbnQgdGVzdE51bWJlciwgUmVhZGVyIGluLCBPdXRwdXRXcml0ZXIgb3V0KSB7CiAgICAgICAgZSA9IGluLm5leHRJbnQoKTsKICAgICAgICByID0gaW4ubmV4dEludCgpOwogICAgICAgIG4gPSBpbi5uZXh0SW50KCk7CgogICAgICAgIGludFtdIHYgPSBpbi5uZXh0SW50QXJyYXkobik7CgogICAgICAgIG91dC5wcmludGxuKCJDYXNlICMiICsgdGVzdE51bWJlciArICI6ICIgKyBzb2x2ZSh2LCAwLCBuLCBlLCAwKSk7CiAgICB9CgogICAgcHJpdmF0ZSBsb25nIHNvbHZlKGludFtdIHYsIGludCBmcm9tLCBpbnQgdG8sIGxvbmcgc3RhcnRFLCBsb25nIHRvRSkgewoKICAgICAgICBpZihmcm9tID09IHRvKQogICAgICAgICAgICByZXR1cm4gMDsKCgogICAgICAgIGludCBpbmRleCA9IGZyb207CgogICAgICAgIGZvcihpbnQgaSA9IGZyb207IGkgPCB0bzsgKytpKXsKICAgICAgICAgICAgaWYodltpXSA+IHZbaW5kZXhdKQogICAgICAgICAgICAgICAgaW5kZXggPSBpOwogICAgICAgIH0KCiAgICAgICAgbG9uZyBzdGFydEhlcmUgPSBNYXRoLm1pbihlLCBzdGFydEUgKyAoaW5kZXggLSBmcm9tKSAqIHIpOwogICAgICAgIGxvbmcgZW5kSGVyZSA9IE1hdGgubWF4KDAsIHRvRSAtICh0byAtIGluZGV4IC0gMSkgKiByKTsKCiAgICAgICAgcmV0dXJuIHNvbHZlKHYsIGZyb20sIGluZGV4LCBzdGFydEUsIE1hdGgubWF4KHN0YXJ0SGVyZSAtIHIsIDApKSArIChzdGFydEhlcmUgLSBlbmRIZXJlKSAqIDFMICogdltpbmRleF0gKyBzb2x2ZSh2LCBpbmRleCArIDEsIHRvLCBNYXRoLm1pbihlLCByICsgZW5kSGVyZSksIHRvRSk7CgogICAgfQp9Cg==
compilation info
Main.java:6: error: class ManageYourEnergy is public, should be declared in a file named ManageYourEnergy.java
public class ManageYourEnergy {
^
Main.java:3: error: package io does not exist
import io.Reader;
^
Main.java:4: error: package io does not exist
import io.OutputWriter;
^
Main.java:9: error: cannot find symbol
public void solve(int testNumber, Reader in, OutputWriter out) {
^
symbol: class Reader
location: class ManageYourEnergy
Main.java:9: error: cannot find symbol
public void solve(int testNumber, Reader in, OutputWriter out) {
^
symbol: class OutputWriter
location: class ManageYourEnergy
5 errors
stdout