Hint on Optimizing the solution

problem link
Solution

I have the brute force solution and it passed all the testcases .
Can someone help me in optimizing it more.
@carre @everule1 or anyone who can help

Thank You.

1 Like

I guess you can optimise the time complexity using Segment Trees.

1 Like

Editorial was already given along with the problem.

Code
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, T;
    cin >> N >> T;

    vector <int> width(N);
    for(int i = 0; i < N; ++i) {
        cin >> width[i];
    }

    for(int i = 0; i < T; ++i) {
        int l, r;
        cin >> l >> r;
    
        int ans = width[l];
        while(l <= r) {
            ans = min(ans, width[l]);
            l++;
        }
        cout << ans << "\n";
    }
    return 0;
}

That Solution was written by me. I think you didn’t understood my question :sweat_smile:.Anyways suman has helped me out. Thanks for your time.