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

New test
Posted by Cadovvl 11 Aug 2012 20:01
My solution of 1005 problem was accepted. Here it is:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,t;
    vector<int> w;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> t;
        w.push_back(t);
    }
    sort(w.begin(), w.end());
    vector<int>::reverse_iterator it = w.rbegin();
    vector<int>::reverse_iterator end = w.rend();
    int s = 0;
    for(; it != end; ++it) s += *it;
    it = w.rbegin();
    s = s/2 + (s%2);
    int l = 0, r = 0;
    for(; it != end; ++it)
        if(l + *it <= s)
            l += *it;
        else
            r += *it;
    cout << abs(l-r) << endl;
    return 0;
}


But there is a test, where this solution gives a wrong answer:
6
101 51 51 3 2 2

Re: New test
Posted by Andrew Sboev [USU] 11 Aug 2012 20:16
Yeah, right answer is 0, but your 2.. I hope that admins will add some new tests.

Edited by author 11.08.2012 20:16
Re: New test
Posted by Sergey Naumenko (MUCTR) 14 Dec 2012 20:13
They did not