|
|
Try this test: 9 6 2 3 2 5 3 4 1 6 1 Answer: 8 1 6 1 2 2 5 3 4 3 sort, read from head and tail\ if head+tail>maximum -> add head,tail to the answers (in front),\ otherwise, add head to answers (to the back)\ wow! interesting observation though Thanks!!! Had the same problem at the beginning, but finally solved it. Good test that helped me to find a bug in my algorithm was: 3 6 2 1 5 When the solution is: 2 (not 3) 2 5 1 Edited by author 24.03.2014 16:32 Edited by author 24.03.2014 16:33 Why two? need to output the maximum amount of trips of the elevator. I dont understand it. plz help Try this: 6 15 6 10 6 9 7 1 I think your answer is: 4 6 10 6 9 7 1 But answer like: 5 6 10 7 9 6 1 5 22 8 15 6 6 14 answer 4 8 15 14 6 6 The answer of simple test not one, right this answer too: 6 6 1 2 3 3 4 5 5 2 5 3 4 3 1 It's hepled me. Sorry, for bad English. Some tests: 6 6 1 2 3 4 5 6 6 1 6 2 5 3 4 6 3 1 2 3 2 1 1 5 1 3 2 2 1 1 10 10 6 3 4 5 2 10 10 5 4 1 8 1 10 2 10 5 6 5 4 4 3 1 6 6 1 6 2 3 3 3 2 3 3 3 3 2 2 1 2 2 2 1 3 3 2 3 2 3 2 3 2 3 3 2 2 3 3 2 3 2 3 3 1 1 3 3 1 3 1 6 6 5 5 5 1 1 1 4 5 5 5 1 1 1 6 7 6 6 6 2 2 2 6 2 6 2 6 2 6 6 8 6 6 6 2 2 2 4 6 6 6 2 2 2 Edited by author 10.07.2014 03:47 Please some body tell me why i am gettig wrong answer in this. My code is: #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <string.h> #include <cstdlib> #include <sstream> #include <stack> #include <queue> #include <numeric> #include <utility> #include <cctype> #include <list> #include <climits> #include <signal.h> #include <ctime> #include <map> #include <set> using namespace std; #define ll long long int ll i, j, k, ct=0, m, n, t, x, y, z, tc, a[200000],s; vector<ll> ans; int main(){ cin >> n >> s; for(i = 0; i < n; i++){ cin >> a[i]; } sort(a,a+n); for ( i = n-1; i > 0 ; i-- ) { if ( a[i] + a[i-1] <= s ) { break; } } // cout << x << " " << y << endl; if(s%2==0){ x = i+1; y = i; //z = n-1; while ( x < n && y >= 0 ) { ans.push_back( a[y] ); ans.push_back( a[x] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } else { y = i; while ( i < n && a[i] == a[y]){ ans.push_back( a[i] ); i++; } y--; x = i; while ( x < n && y >= 0 ) { ans.push_back( a[x] ); ans.push_back( a[y] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } ct = 0; for ( i = 0; i < ans.size(); ) { if( i == ans.size() - 1){ ct++; i++; } else{ if( ans[i] + ans[i+1] <= s){ ct++; i+=2; } else{ ct++; i++; } } } cout << ct << endl; for ( i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } return 0; } Edited by author 13.10.2012 20:42 |
|
|