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 1005. Stone Pile

Compilation error, why ?
Posted by ByteJumper 22 Mar 2008 14:18
On my linux machine it works fine, when I submit the problem a got compilation error.

#include <iostream>
#include <vector>
using namespace std;
int data;
int last;
vector <int> base;
int pile[2];
vector <int>::iterator it;

int getMax(){
    it=base.end()-1;
    pile[0]+= *it;
    base.erase(it);
    return *it;
}

int getRest(int value){
    int all = 0;
    while(!base.empty()){
        it=base.end()-1;
        all += *it;
        if(value >= all){
            pile[1]+= *it;
            base.erase(it);
        }
        else{
            break;
        }

    }
    return 0;
}

int main(){
    last = 0;
    pile[0] = 0;
    cin >> data;
    while(cin >> data){
        base.push_back(data);
    }
    sort(base.begin(),base.end());
    while(!base.empty()){
        last = getMax();
        getRest(last);
    }
    if(pile[1] >= pile[0]){
    cout << pile[1] - pile[0];
    }
    else{
    cout << pile[0] - pile[1];
    }
    return 0;
}

Edited by author 22.03.2008 14:23