HEU 5016 Exchange Apples

 1 /**************************************
 2Problem: HEU 5016 Exchange Apples
 3Time: 0.0100 s
 4Memory: 248 k 
 5Accepted Time: 2009-03-30 17:11:56
 6Tips: 满足第一个元素,只能从第二个元素里得到满足,以此类推 
 7**************************************/

 8 #include  < stdio.h >
 9 #define  abs(x) (x>0?x:-x)
10 int  main()
11 {
12    int tt,n,i,j,k,a[100009];
13    scanf("%d",&tt);
14    while(tt--)
15    {
16        int sum=0;
17        scanf("%d",&n);
18        for(i=0;i<n;i++)scanf("%d",&a[i]);
19        for(i=0;i<n-1;i++)
20        {
21            sum+=abs(a[i]);
22            a[i+1]+=a[i];
23        }

24        printf("%d\n",sum);     
25    }
     
26    return 0;
27}
     
28

你可能感兴趣的:(Exchange)