|  | 
|  | 
| back to board | Accepted whis wrong answer Posted by Actics  29 Jun 2011 04:25See, this is my code. For 4 stone (48 22 27 3) he said: 4. But correct answer is 2!
 --------------------------------------------------
 
 #include <stdio.h>
 #include <algorithm>
 using namespace std;
 int main() {
 int n, i, s=0, x, y=0, *m;
 scanf("%d", &n);
 m = new int[n];
 for (i=0; i<n; i++) {
 scanf("%d", &m[i]);
 s += m[i];
 }
 s /= 2;
 sort(m, m+n);
 x = m[n-1];
 for (i=n-2; i>-1; i--)
 if (x+m[i] <= s)
 x += m[i];
 else
 y += m[i];
 printf("%d", (x>y)?(x-y):(y-x));
 return 0;
 }
 
 Edited by author 29.06.2011 04:25
 | 
 | 
|