Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- using namespace std;
- void solve(int years){
- int num_popes;
- cin >> num_popes;
- vector<int> popes;
- while(num_popes--){
- int pope;
- cin >> pope;
- popes.push_back(pope);
- }
- int curr_popes = 0, best = 0, first_year = 0, last_year = 0;
- int answer_start, answer_end;
- while (last_year < popes.size()){
- int difference = popes[last_year] - popes[first_year];
- if (difference < years) {
- ++last_year;
- } else {
- ++first_year;
- }
- difference = popes[last_year] - popes[first_year];
- curr_popes = last_year - first_year + 1;
- if (curr_popes > best && difference < years && last_year < popes.size()) {
- best = curr_popes;
- answer_start = first_year;
- answer_end = last_year;
- }
- }
- cout << best << " " << popes[answer_start]<< " " << popes[answer_end] << endl;
- }
- int main(){
- int year;
- while(cin >> year){
- solve(year);
- }
- }
Add Comment
Please, Sign In to add comment