Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(){
- int x,y,max,min;
- while(scanf("%d %d",&x,&y)!=EOF)
- {
- int a[x+1],b[y+1],c[y+1];
- for(int i=1;i<=x;i++)
- {
- scanf("%d",&a[i]);
- }
- for(int j=1;j<=y;j++)
- {
- scanf("%d %d", &b[j],&c[j]);
- }
- for(int k=1;k<=y;k++)
- {
- max=0;
- min=2000000;
- for(int l=b[k];l<=c[k];l++)
- {
- if(a[l]>max)
- max=a[l];
- if(a[l]<min)
- min=a[l];
- }
- printf("%d\n",max-min);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement