MSBOP 2015 Round3 register

Ended

Participants:978

Verdict:AC | TLE
Submitted:2015-05-09 15:11:26

Lang:G++

Edit
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
#include <iostream>
#include <cstdio>
using namespace std;
int a[1111],q,n,T,cas=0;
int main(){
    scanf("%d",&T);
    while (T--){
        scanf("%d%d",&n,&q);
        for (int i=1; i<=n; i++) scanf("%d",&a[i]);
        printf("Case #%d:\n",++cas);
        while (q--){
            int L,R,K;
            scanf("%d%d%d",&L,&R,&K);
            int ans=1111111111;
            for (int i=L; i<=R; i++){
                if (a[i]>=K) ans=min(ans,a[i]-K);
                    else ans=min(ans,K-a[i]);
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX