Submission #225194

# Submission time Handle Problem Language Result Execution time Memory
225194 2020-04-19T14:00:50 Z Vimmer Simfonija (COCI19_simfonija) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define MOD ll(998244353)

using namespace std;

typedef long long ll;

typedef long double ld;


int main()
{

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, k;

    cin >> n >> k;

    ll a[n], b[n], pr[n + 1];

    pr[n] = 0;

    for (ll i = 0; i < n; i++) cin >> a[i];

    for (ll i = 0; i < n; i++) cin >> b[i];

    vector <ll> g(n);

    for (ll i = 0; i < n; i++) g[i] = a[i] - b[i];

    sort(g.begin(), g.end());

    g.pb(1e18);

    for (ll i = 0; i < n; i++)
    {
        pr[i] = 0;

        if (i != 0) pr[i] = pr[i - 1];

        pr[i] += g[i];
    }

    ll ans = 1e18, l = 0, r = n - k - 1;

    while (r < n)
    {
        ll mdr = (r - l + 1) / 2;

        ll mdl = mdr - 1;

        if (mdr >= 0 && mdr < n)
        {
            ll x = g[mdr];

            int pos = upper_bound(g.begin(), g.end(), x) - g.begin();

            int posr = lower_bound(g.begin(), g.end(), 0);

            if (x < 0)
            {
                ll sum = 0;

                if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));

                if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));

                sum += pr[min(r, posr - 1)] - (max(pos, l) == 0 ? 0 : p[max(pos, l) - 1]) + abs(x * (min(posr - 1, r) - max(pos, l) + 1));

                ans = min(ans, sum);
            }
            else
            {
                ll sum = 0;

                if (posr - 1 >= l) sum = (posr - l) * x + abs(pr[posr - 1] - (l == 0 ? 0 : pr[l - 1]));

                if (pos <= r) sum += (r - pos)

                sum += pr[min(r, pos - 1)] - (max(posr, l) == 0 ? 0 : pr[max(posr, l) - 1]) - x * (min(r, pos) - max(posr, l) + 1);

                ans = min(ans, sum);
            }
        }
        l++; r++;
    }

    cout << ans << endl;
}

Compilation message

simfonija.cpp: In function 'int main()':
simfonija.cpp:71:57: error: cannot convert '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'int' in initialization
             int posr = lower_bound(g.begin(), g.end(), 0);
                                                         ^
simfonija.cpp:77:58: error: no matching function for call to 'max(int&, ll&)'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                          ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                          ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                          ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                          ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                          ^
simfonija.cpp:77:73: error: 'p' was not declared in this scope
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                         ^
simfonija.cpp:77:92: error: no matching function for call to 'max(int&, ll&)'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                            ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:92: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                            ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:92: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                            ^
simfonija.cpp:77:118: error: no matching function for call to 'max(int&, ll&)'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                                                      ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:118: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                                                      ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:118: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                                                      ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:118: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                                                      ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
simfonija.cpp:77:118: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (posr <= r) sum = abs((r - max(posr, l) + 1) * x) + (p[r] - (max(posr, l) == 0 ? 0 : p[max(posr, l) - 1]));
                                                                                                                      ^
simfonija.cpp:79:59: error: no matching function for call to 'min(int, ll&)'
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                           ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
simfonija.cpp:79:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                           ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
simfonija.cpp:79:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                           ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
simfonija.cpp:79:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                           ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
simfonija.cpp:79:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                           ^
simfonija.cpp:79:110: error: no matching function for call to 'min(int, ll&)'
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                                                                              ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
simfonija.cpp:79:110: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l == 0 ? 0 : pr[l - 1]) - x * (min(pos - 1, r) - l + 1));
                                                                                                              ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from simfonija.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
simfonija.cpp:79:110: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll {aka long long int}')
                 if (pos >= l) sum += abs(pr[min(pos - 1, r)] - (l