Pagini recente » Cod sursa (job #1741160) | Cod sursa (job #721306) | Cod sursa (job #1738566) | Cod sursa (job #2955701) | Cod sursa (job #3345460)
import java.io.*;
public class Main {
static class FastScanner {
private final InputStream in;
private final byte[] buffer = new byte[1 << 16];
private int ptr = 0, len = 0;
FastScanner(String fileName) throws IOException {
in = new FileInputStream(fileName);
}
private int read() throws IOException {
if (ptr >= len) {
len = in.read(buffer);
ptr = 0;
if (len <= 0) return -1;
}
return buffer[ptr++];
}
int nextInt() throws IOException {
int c;
do {
c = read();
} while (c <= ' ');
int sign = 1;
if (c == '-') {
sign = -1;
c = read();
}
int x = 0;
while (c > ' ') {
x = x * 10 + (c - '0');
c = read();
}
return x * sign;
}
void close() throws IOException {
in.close();
}
}
public static void main(String[] args) throws Exception {
FastScanner fs = new FastScanner("ssm.in");
int N = fs.nextInt();
int bestSum = Integer.MIN_VALUE;
int bestL = 1, bestR = 1;
int currentSum = 0;
int currentL = 1;
for (int i = 1; i <= N; i++) {
int x = fs.nextInt();
if (currentSum < 0) {
currentSum = x;
currentL = i;
} else {
currentSum += x;
}
if (currentSum > bestSum ||
(currentSum == bestSum && currentL < bestL) ||
(currentSum == bestSum && currentL == bestL && i - currentL < bestR - bestL)) {
bestSum = currentSum;
bestL = currentL;
bestR = i;
}
}
fs.close();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ssm.out")));
out.println(bestSum + " " + bestL + " " + bestR);
out.close();
}
}