HUD5443

HUD 5443 The Water Problem

AC Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int ncase;
scanf("%d", &ncase);
while(ncase--) {
int n;
scanf("%d", &n);
int inp[n];
for(int i = 0; i < n; i++)
scanf("%d", &inp[i]);
int q;
scanf("%d", &q);
for(int i = 0; i < q; i++) {
int l, r;
scanf("%d %d", &l, &r);
l--;
r--;
int mx = 0;
for(int j = l; j <= r; j++) {
mx = max(mx, inp[j]);
}
printf("%d\n", mx);
}
}
return 0;
}