[Offer收割]编程练习赛83 register

Ended

Participants:85

Verdict:Accepted
Score:100 / 100
Submitted:2018-11-18 12:11:44

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
 #include<bits/stdc++.h>
 using namespace std;
 long long s[100005];
 long long a[100005];
 int main()
 {
     int n,m;
     scanf("%d%d",&n,&m);
     s[0]=0;
     for(int i=1;i<=n;i++)
     {
        scanf("%lld",&a[i]);
        s[i]=s[i-1]+a[i];
     }
     int x,y;
     while(m--)
     {
         scanf("%d%d",&x,&y);
         if(x>y) swap(x,y);
         printf("%lld\n",min(s[y-1]-s[x-1],s[n]-(s[y-1]-s[x-1])));
     }
     return 0;
 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX