Created
April 26, 2016 07:56
-
-
Save PreSoichiSumi/ab914f62c6bca9f70c95458b5c04f234 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.*; | |
public class Main { | |
private static final double EPS = 1e-10; | |
public static int a[]; | |
public static void main(String args[]) { | |
FastScanner sc = new FastScanner(); | |
int n = sc.nextInt(); | |
a=new int[n]; | |
for(int i=0;i<n;i++){ | |
a[i]=sc.nextInt(); | |
} | |
int aokiIndex; | |
int maxTKHSScore=-Integer.MAX_VALUE; | |
int tmp; | |
for(int i=0;i<n;i++){//高橋の選んだ手 | |
aokiIndex=getAokiIndex(i); | |
tmp=calcTKHSScore(i,aokiIndex); | |
if(maxTKHSScore<tmp){ | |
maxTKHSScore=tmp; | |
} | |
} | |
System.out.println(maxTKHSScore); | |
} | |
//青木をシミュレートして,青木が選ぶとこを返す | |
public static int getAokiIndex(int tkhs){ | |
int maxIndex=-1; | |
int max=-100; | |
int tmp; | |
for(int i=0;i<a.length;i++){ | |
if(tkhs==i)continue; | |
tmp=calcAokiScore(tkhs,i); | |
if(max<tmp){ | |
max=tmp; | |
maxIndex=i; | |
} | |
} | |
return maxIndex; | |
} | |
//高橋が得る点数を返す | |
public static int calcTKHSScore(int tkhs, int aoki){ | |
int min=Math.min(tkhs,aoki); | |
int max=Math.max(tkhs,aoki); | |
boolean flag=true; | |
int res=0; | |
for(int i=min; i<=max; i++){ | |
if(flag){ | |
res+=a[i]; | |
} | |
flag=!flag; | |
} | |
return res; | |
} | |
//青木が得る点数を返す | |
public static int calcAokiScore(int tkhs, int aoki){ | |
int min=Math.min(tkhs,aoki); | |
int max=Math.max(tkhs,aoki); | |
boolean flag=false; | |
int res=0; | |
for(int i=min; i<=max; i++){ | |
if(flag){ | |
res+=a[i]; | |
} | |
flag=!flag; | |
} | |
return res; | |
} | |
} | |
class FastScanner { | |
private final InputStream in = System.in; | |
private final byte[] buffer = new byte[1024]; | |
private int ptr = 0; | |
private int buflen = 0; | |
private boolean hasNextByte() { | |
if (ptr < buflen) { | |
return true; | |
} else { | |
ptr = 0; | |
try { | |
buflen = in.read(buffer); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
if (buflen <= 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
private int readByte() { | |
if (hasNextByte()) return buffer[ptr++]; | |
else return -1; | |
} | |
private boolean isPrintableChar(int c) { | |
return 33 <= c && c <= 126; | |
} | |
private void skipUnprintable() { | |
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; | |
} | |
public boolean hasNext() { | |
skipUnprintable(); | |
return hasNextByte(); | |
} | |
public String next() { | |
if (!hasNext()) throw new NoSuchElementException(); | |
StringBuilder sb = new StringBuilder(); | |
int b = readByte(); | |
while (isPrintableChar(b)) { | |
sb.appendCodePoint(b); | |
b = readByte(); | |
} | |
return sb.toString(); | |
} | |
public long nextLong() { | |
if (!hasNext()) throw new NoSuchElementException(); | |
long n = 0; | |
boolean minus = false; | |
int b = readByte(); | |
if (b == '-') { | |
minus = true; | |
b = readByte(); | |
} | |
if (b < '0' || '9' < b) { | |
throw new NumberFormatException(); | |
} | |
while (true) { | |
if ('0' <= b && b <= '9') { | |
n *= 10; | |
n += b - '0'; | |
} else if (b == -1 || !isPrintableChar(b)) { | |
return minus ? -n : n; | |
} else { | |
throw new NumberFormatException(); | |
} | |
b = readByte(); | |
} | |
} | |
public int nextInt() { | |
if (!hasNext()) throw new NoSuchElementException(); | |
int n = 0; | |
boolean minus = false; | |
int b = readByte(); | |
if (b == '-') { | |
minus = true; | |
b = readByte(); | |
} | |
if (b < '0' || '9' < b) { | |
throw new NumberFormatException(); | |
} | |
while (true) { | |
if ('0' <= b && b <= '9') { | |
n *= 10; | |
n += b - '0'; | |
} else if (b == -1 || !isPrintableChar(b)) { | |
return minus ? -n : n; | |
} else { | |
throw new NumberFormatException(); | |
} | |
b = readByte(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment