Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- pair<int, int> BiggestIncreasingSubs(const vector<int>& arr){
- int l = -1;
- int r = -1;
- int biggest_len = 0;
- int cur_l = 0;
- for (int i = 0; i < arr.size() - 1; ++i){
- if (arr[i] > arr[i+1]){
- if (i - cur_l + 1 > biggest_len){
- l = cur_l;
- r = i;
- biggest_len = i - cur_l + 1;
- }
- cur_l = i + 1;
- }
- }
- if (arr.size() - cur_l > biggest_len){
- l = cur_l;
- r = arr.size() - 1;
- }
- return {l, r};
- }
- int main() {
- int n;
- cin >> n;
- vector<int> v(n);
- for (int i = 0; i < n; ++i) {
- cin >> v[i];
- }
- auto ans1 = BiggestIncreasingSubs(v);
- reverse(v.begin(), v.end());
- auto ans2 = BiggestIncreasingSubs(v);
- if (ans1.second - ans1.first > ans2.second - ans1.first){
- cout << ans1.first << " " << ans1.second;
- } else {
- cout << v.size() - 1 - ans2.second << " " << v.size() - ans1.first - 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement