mirror of
https://github.com/xlucn/PAT.git
synced 2026-08-18 09:28:49 +08:00
add a1046
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int N, M, start, end, d, D[100001] = {0};
|
||||
|
||||
scanf("%d", &N);
|
||||
for(int i = 0; i < N; i++)
|
||||
{
|
||||
scanf("%d", D + i + 1);
|
||||
/* record the distance between the current and the first exits */
|
||||
D[i + 1] += D[i];
|
||||
}
|
||||
|
||||
scanf("%d", &M);
|
||||
for(int i = 0; i < M; i++)
|
||||
{
|
||||
scanf("%d %d", &start, &end);
|
||||
d = --start > --end ? D[start] - D[end] : D[end] - D[start];
|
||||
/* if the distance is more than half total length, the other direction will be shorter */
|
||||
printf("%d\n", d * 2 > D[N] ? D[N] - d : d);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user