|
|
back to boardsolution I've got AC on this solution. This solution isn't bruteforce #include <iostream> using namespace std; int* sort(int*, int); int main() { int N; cin>>N; int *W = new int[N]; for(int i=0;i<N;i++) { cin>>W[i]; } sort(W,N); int pipe1=0; int pipe2=0; int weight=0; for(int i=0;i<N;i++) { weight+=W[i]; } for(int i=0;i<N;i++) { if((pipe1+W[i])<=weight-W[i]) { pipe1+=W[i]; weight-=W[i]; } else { pipe2+=W[i]; weight-=W[i]; } if(pipe1<pipe2) { int temp=pipe1; pipe1=pipe2; pipe2=temp; } } cout<<pipe1-pipe2; return 0; } where sort()is back ordered sort Re: solution Fails on { 2, 2, 3, 4, 5}. Should be 0 ({2, 2, 4} - {5, 3}), but returns 2 ({5, 2, 2} - {4, 3}). |
|
|