-
Notifications
You must be signed in to change notification settings - Fork 2
/
A1046.cpp
52 lines (49 loc) · 897 Bytes
/
A1046.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
43
44
45
46
47
48
49
50
51
52
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 10;
int dis[MAXN] = {0};
int A[MAXN] = {0};
int N, M, sum = 0;
int main(){
scanf("%d", &N);
for(int i = 1; i <= N; ++i){
scanf("%d", &A[i]);
sum += A[i];
dis[i] = sum;
}
scanf("%d", &M);
for(int i = 0; i < M; ++i){
int a, b;
scanf("%d%d", &a, &b);
if(a > b) swap(a, b);
if(a == b){
printf("0\n");
continue;
}
int tmp = dis[b-1] - dis[a-1];
printf("%d\n", min(tmp, sum - tmp));
/**
int shortest = 0;
int cnt = b - a + 1;
if(cnt * 2 < N){
for(int j = a; j < b; ++j){
shortest += dis[j];
}
}else{
for(int j = 1; j < a; ++j){
shortest += dis[j];
}
for(int j = b; j <= N; ++j){
shortest += dis[j];
}
}
if(shortest * 2 > sum){
shortest = sum - shortest;
}
printf("%d", shortest);
if(i != M - 1) printf("\n");
**/
}
return 0;
}