-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1046.cpp
42 lines (40 loc) · 845 Bytes
/
1046.cpp
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
40
41
42
//
// 1046.cpp
// 算法
//
// Created by 王怡凡 on 2017/8/23.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include <stdio.h>
const int maxn = 100010;
int n,dis[maxn];
int main() {
scanf("%d",&n);
int i,m,query1,query2,all=0;
dis[1] = 0;
for(i=2;i<=n+1;i++) {
scanf("%d",&dis[i]);
dis[i] = dis[i] + all;
all = dis[i];
}
scanf("%d",&m);
int sum;
for(i=0;i<m;i++) {
scanf("%d%d",&query1,&query2);
if(query1==query2) {
printf("0\n");
continue;
}
if(query1>query2) {
int t = query1;
query1 = query2;
query2 = t;
}
sum = dis[query2] - dis[query1];
if(sum>all-sum) {
sum = all-sum;
}
printf("%d\n",sum);
}
return 0;
}