|
|
вернуться в форумWy WA???????? 1005(C++) Послано faust 22 сен 2002 13:40 #include <iostream.h> #include <stdlib.h> void main(void) { int N; cin >> N; long *w = new long [N]; long p1 = 0; long p2 = 0; int pile = 1; for(int i = 0 ; i < N ; ++i) cin >> w[i]; for(i = 0 ; i < N - 1 ; ++i) { for(int j = i + 1 ; j < N ; ++j) { if(w[j] > w[i]) { long tmp = w[i]; w[i] = w[j]; w[j] = tmp; }; }; }; for(i = 0 ; i < N ; ++i) { if(pile == 1) { p1 += w[i]; if(p1 > p2) pile = 2; }else { p2 += w[i]; if(p2 > p1) pile = 1; }; }; cout << abs(p1 - p2); delete [] w; }; I know :( Послано faust 22 сен 2002 14:06 |
|
|