|
|
вернуться в форум#include<stdio.h> int main(){ int stonenumber; int i,j; long int s=0,t=0,a[20],u,minweight; scanf("%d",&stonenumber); for(i=0;i<stonenumber;i++) scanf("%d",&a[i]); for(j=0;j<stonenumber-1;j++) for(i=0;i<stonenumber-j-1;i++) if(a[i]>a[i+1]) {u=a[i];a[i]=a[i+1];a[i+1]=u;} s=a[stonenumber-1]; t=a[stonenumber-2]; for(i=stonenumber-3;i>=0;i--) if(t<s||t==s) t=t+a[i]; else s=s+a[i]; if(s>t) minweight=s-t; else minweight=t-s; printf("%d",minweight); return 0; } please reply me:287662136@163.com Edited by author 05.05.2005 09:07 Edited by author 05.05.2005 09:07 5 2000 3 4 5 6 The correct answer should be 1988,and what's your answer? how can be the correct answer 1988 if we put one stone 2000 in then one heap and other stones (3+4+5+6=18) in then second heap? 2000-18=1982 not a 1988 yeah, my answer is 1982, but I have wrong answer on test 1 Can you explain your solution? I'm struck with test 5! try this test: 5 3 3 2 2 2 the correct answer is 0. your program gives 2. Edited by author 24.11.2007 02:22 |
|
|