CSES - Putka Open 2015 – 1/6 - Results
Submission details
Task:Jakkara
Sender:
Submission time:2015-07-17 18:05:43 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.

Code

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_map>
#define N 2048
#define M 1000000007

using namespace std;

int main()
{
    vector<int> v;
    set<int> s;
    int sum = 0;
    for (int i = 0; i < 4; i++) {
        int x;
        cin>>x;
        sum += x;
        s.insert(x);
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    if (s.size() == 1) cout<<0<<endl;
    else if (s.size() == 2) {
        if (v[0] == v[1] && v[2] == v[3]) cout<<2 * (v[2] - v[0])<<endl;
        else if (v[0] == v[1]) {
            cout<<(v[3] - v[0])<<endl;
        } else {
            cout<<(v[0] - v[3])<<endl;
        }
    } else if (s.size() == 3) {
        if (v[0] == v[1]) cout<<v[2] - v[0] + v[3] - v[0]<<endl;
        else if (v[2] == v[1]) cout<<v[2] - v[0] + v[3] - v[2]<<endl;
        else cout<<v[2] - v[0] + v[2] - v[1]<<endl;
    } else {
        int div = sum / 4;
        int ans = abs(v[0] - div) + abs(v[1] - div) + abs(v[2] - div) + abs(v[3] - div);
        div++;
        ans = min(ans, abs(v[0] - div) + abs(v[1] - div) + abs(v[2] - div) + abs(v[3] - div));
        cout<<ans<<endl;
    }
}