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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:29:28: error: no matching function for call to 'min(long long int&, int&)'
         mi = min(t[i].F, mi);
                            ^
input/code.cpp:29:28: note: candidates are:
In file included from /usr/include/c++/4.9/bits/char_traits.h:39:0,
                 from /usr/include/c++/4.9/ios:40,
                 from /usr/include/c++/4.9/ostream:38,
                 from /usr/include/c++/4.9/iostream:39,
                 from input/code.cpp:1:
/usr/include/c++/4.9/bits/stl_algobase.h:194:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/4.9/bits/stl_algobase.h:194:5: note:   template argument deduction/substitution failed:
input/code.cpp:29:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
         mi = min(t[i].F, mi);
                            ^
In file included from /usr/include/c++/4.9/bits/cha...

Code

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N = 37e6;
pair<ll, ll> t[111];
ll mod = 98765431;
ll asd = 1007;
bool comp(pair<ll, ll> a, pair<ll, 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;
    int mi = 1e9;
    for(int i = 0; i < n; ++i) {
        cin>>t[i].F;
        t[i].S = i;

        sum += t[i].F;
        mi = min(t[i].F, mi);
    }
    if(mi >= 500) return -1;
    sort(t, t+n, comp);
    for(int i = 0; i < N/n; ++i) {
        //random_shuffle(t, t+n);
        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].F;
                a -= t[j].F;
                v[t[j].S] = 1;
            }
            else {
                left -= t[j].F;
                v[t[j].S] = 2;
            }
        }
        a = abs(a);
        best = min(best, {a, v});
    }
    for(int i = 0; i < n; ++i) {
        cout<<best.S[i]<<' ';
    }
    cout<<'\n';
}