ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1901. Space Elevators

Wrong Answer :(
Posted by Udit Agarwal 13 Oct 2012 20:41
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