Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by dang71 ( 6 years ago )
#include <stdio.h>
void swap(int *a, int *b){
if(*a > *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
}
int main(){
int n, x, y, s1=0, s2=0;
scanf("%d%d%d", &n, &x, &y); // x<y
swap(&x, &y);
int A[n], i, j;
for(i=0; i<n; i++){
scanf("%d", &A[i]);
}
i = x;
j = y;
while(1){
if(j==n+1) j = 1;
if(i!=y) s1 += A[i-1];
if(j!=x) s2 += A[j-1];
if((i==y && s1 <= s2)){
break;
}
if(j==x && s2 <= s1){
break;
}
if(i!=j) i++;
if(j!=x) j++;
}
swap(&s1, &s2);
printf("%d", s1);
return 0;
}
Revise this Paste