-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooks.cpp
71 lines (63 loc) · 1.16 KB
/
Books.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Rodrigo Farias de Macêdo
#include <string>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <iterator>
#include <math.h>
using namespace std;
int contaLivros(int array[], int i, int time, int end){
int soma = 0;
int l = i-1, r = i+1;
if(time > array[i]){
time -= array[i];
soma++;
while((l >= 0 || r < end) && time > 0){
if(l >=0 && array[l] < array[r]){
if(time > array[l]){
time -= array[r];
soma++; l--;
}else{
l--;
}
}else if(r < end && array[r] < array[l]){
if(time > array[r]){
time -= array[r];
soma++; r++;
}else{
r++;
}
}
}
}
return soma;
}
int main(){
int b, t, l=0;
scanf("%d %d", &b, &t);
int r = b-1;
int boo[b];
for (int i = 0; i < b; i++){
cin >> boo[i];
}
int lidos, max=0;
while(l <= r){
lidos = contaLivros(boo, r-1, t, b);
if(lidos > max){
max = lidos;
}
// cout << lidos << "lidos r " << r << endl;
lidos = revContaLivros(boo, t, r);
if(lidos > max){
max = lidos;
r-= max ;
}
r--;
// cout << lidos << "lidos r " << r << endl;
}
cout << max << endl;
return 0;
}