Submission #995262

# Submission time Handle Problem Language Result Execution time Memory
995262 2024-06-08T17:48:09 Z gmroh06 Just Long Neckties (JOI20_ho_t1) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

template <typename T> class arr {
private:
    vector<T> v;

public:
    arr(const ll& n) {
        v.resize(n);
    }

    vector<T>::iterator begin() {
        return v.begin();
    }

    vector<T>::iterator end() {
        return v.end();
    }

    T& operator [] (const ll& idx) {
        return v[idx];
    }

    friend ostream& operator << (ostream& out, const arr& x) {
        for (auto &i : x.v) {
            out << i << ' ';
        }

        return out;
    }

    friend istream& operator >> (istream& in, arr& x) {
        for (auto &i : x.v) {
            in >> i;
        }

        return in;
    }
};

ll n;

int main() {
    fastio();

    cin >> n;

    arr<ll> v(n), ans(n + 1);
    arr<pll> p(n + 1);

    for (ll i = 0, x; i <= n; i++) {
        cin >> x;
        p[i] = {x, i};
    }

    cin >> v;

    sort(v.begin(), v.end());
    sort(p.begin(), p.end());

    multiset<ll> ms;

    for (ll i = 0; i < n; i++) {
        ms.insert(max(0LL, p[i + 1].first - v[i]));
    }

    for (ll i = 0; i <= n; i++) {
        auto it = ms.end();
        ans[p[i].second] = *(--it);

        if (i != n) {
            it = ms.lower_bound(max(0LL, p[i + 1].first - v[i]));
            ms.erase(it);
            ms.insert(max(0LL, p[i].first - v[i]));
        }
    }

    cout << ans << '\n';

    return 0;
}

Compilation message

ho_t1.cpp:22:5: error: need 'typename' before 'std::vector<_Tp>::iterator' because 'std::vector<_Tp>' is a dependent scope
   22 |     vector<T>::iterator begin() {
      |     ^~~~~~~~~
      |     typename 
ho_t1.cpp:26:5: error: need 'typename' before 'std::vector<_Tp>::iterator' because 'std::vector<_Tp>' is a dependent scope
   26 |     vector<T>::iterator end() {
      |     ^~~~~~~~~
      |     typename 
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:68:12: error: 'class arr<long long int>' has no member named 'begin'
   68 |     sort(v.begin(), v.end());
      |            ^~~~~
ho_t1.cpp:68:23: error: 'class arr<long long int>' has no member named 'end'
   68 |     sort(v.begin(), v.end());
      |                       ^~~
ho_t1.cpp:69:12: error: 'class arr<std::pair<long long int, long long int> >' has no member named 'begin'
   69 |     sort(p.begin(), p.end());
      |            ^~~~~
ho_t1.cpp:69:23: error: 'class arr<std::pair<long long int, long long int> >' has no member named 'end'
   69 |     sort(p.begin(), p.end());
      |                       ^~~