# Popes - UVA judge | Andres Salazar & Julian David Ramirez Lopera EAFIT

Oct 22nd, 2021 (edited)
300
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <vector>
2. #include <iostream>
3.
4. using namespace std;
5.
6. void solve(int years){
7.     int num_popes;
8.     cin >> num_popes;
9.     vector<int> popes;
10.
11.     while(num_popes--){
12.         int pope;
13.         cin >> pope;
14.         popes.push_back(pope);
15.     }
16.
17.     int curr_popes = 0, best = 0, first_year = 0, last_year = 0;
19.
20.     while (last_year < popes.size()){
21.
22.         int difference = popes[last_year] - popes[first_year];
23.         if (difference < years) {
24.             ++last_year;
25.         } else {
26.             ++first_year;
27.         }
28.
29.         difference = popes[last_year] - popes[first_year];
30.         curr_popes = last_year - first_year + 1;
31.         if (curr_popes > best && difference < years && last_year < popes.size()) {
32.             best = curr_popes;
35.         }
36.     }
37.
38.     cout << best << " " << popes[answer_start]<< " " << popes[answer_end] << endl;
39. }
40.
41.
42. int main(){
43.     int year;
44.     while(cin >> year){
45.         solve(year);
46.     }
47. }
48.
RAW Paste Data