// Codeforces Round #171 (Div. 2) B. Books
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;// change to false before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int N = in.nextInt();
int T = in.nextInt();
int[] a = new int[N];
for (int i = 0; i < N; i++) {
a[i] = in.nextInt();
}
int[] nbooks = new int[N];
int[] sumtime = new int[N];
for (int first = 0; first < N; first++) {
nbooks[first] = 0;
sumtime[first] = 0;
if (a[first] > T)
continue;
if (first == 0 || nbooks[first - 1] == 0)
{
int sum = 0;
int nb = 0;
for (int k = first; k < N; k++) {
if (sum + a[k] > T)
break;
else {
sum += a[k];
nb++;
}
}
nbooks[first] = nb;
sumtime[first] = sum;
}
else {
int sum = sumtime[first - 1] - a[first - 1];
int k = first + nbooks[first - 1] - 1;
int nb = nbooks[first - 1] - 1;
while (true) {
if (k >= N || sum + a[k] > T)
break;
sum += a[k];
nb++;
k++;
}
nbooks[first] = nb;
sumtime[first] = sum;
}
}
int maxb = 0;
for (int i = 0; i < N; i++) {
maxb = Math.max(maxb, nbooks[i]);
}
out.println(maxb);
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
No comments:
Post a Comment