CSES - Putka Open 2015 – finaali - Results
Submission details
Task:Omenat
Sender:
Submission time:2015-12-20 16:32:26 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:26:16: error: 'sort' was not declared in this scope
     sort(t, t+n);
                ^

Code

#include <iostream>
#include <cstdlib>
#include <vector>
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N = 37e6;
ll t[111];
ll mod = 98765431;
ll asd = 1007;
bool comp(ll a, ll b) {
    return a > b;
}
int main() {
    srand(time(0));
    ll rr = rand()%mod;
    int n;
    cin>>n;
    pair<ll, vector<int> > best = {1e18, {0}};
    ll sum = 0;
    for(int i = 0; i < n; ++i) {
        cin>>t[i];
        sum += t[i];
    }
    sort(t, t+n);
    for(int i = 0; i < N/n; ++i) {
        ll a = sum/2;
        ll left = sum;
        vector<int> v(n);
        for(int j = 0; j < n; ++j) {
            rr *= asd;
            rr %= mod;
            ll r = rr%1000;
            //if(r/1000 < a/left) {
            if(r*left < 1000*a) {
            //if(r < 500) {
                left -= t[j];
                a -= t[j];
                v[j] = 1;
            }
            else {
                left -= t[j];
                v[j] = 2;
            }
        }
        a = abs(a);
        best = min(best, {a, v});
    }
    for(int i = 0; i < n; ++i) {
        cout<<best.S[i]<<' ';
    }
    cout<<'\n';
}