ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1005. Куча камней

Показать все сообщения Спрятать все сообщения

New test Cadovvl 11 авг 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 Andrew Sboev [USU] 11 авг 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 Sergey Naumenko (MUCTR) 14 дек 2012 20:13
They did not