#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e6 + 5;   void compute() {     int n, m;     scanf( %d %d , &n, &m);     vector<int> v(n);     for (int i = 0; i < n; ++i) scanf( %d , &v[i]);     vector<pair<int, int> > seg(m);     vector<vector<int> > lf(n), rg(n);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &seg[i].first, &seg[i].second);       --seg[i].first;       --seg[i].second;       lf[seg[i].second].push_back(seg[i].first);       rg[seg[i].first].push_back(seg[i].second);     }     vector<int> add(n, 0);     vector<int> ansv(n, -inf);     int mn = v[0];     for (int i = 0; i < n; ++i) {       ansv[i] = max(ansv[i], v[i] - mn);       for (auto l : lf[i]) {         for (int j = l; j <= i; ++j) {           --add[j];           mn = min(mn, v[j] + add[j]);         }       }       mn = min(mn, v[i] + add[i]);     }     add = vector<int>(n, 0);     mn = v[n - 1];     for (int i = n - 1; i >= 0; --i) {       ansv[i] = max(ansv[i], v[i] - mn);       for (auto r : rg[i]) {         for (int j = i; j <= r; ++j) {           --add[j];           mn = min(mn, v[j] + add[j]);         }       }       mn = min(mn, v[i] + add[i]);     }     int res = *max_element(ansv.begin(), ansv.end());     vector<int> res2;     for (int i = 0; i < n; ++i) {       if (ansv[i] == res) {         for (int j = 0; j < m; ++j) {           if (!(seg[j].first <= i && seg[j].second >= i)) res2.push_back(j + 1);         }         break;       }     }     printf( %d n%d n , res, (int)res2.size());     for (auto i : res2) printf( %d  , i);     printf(  n );   }   int main() {     compute();     return 0;   }   