Submission #333769

# Submission time Handle Problem Language Result Execution time Memory
333769 2020-12-07T17:47:43 Z HynDuf Kralj (COCI16_kralj) C++11
140 / 140
837 ms 53092 KB
#include <bits/stdc++.h>

#define task "K"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 5e5 + 2;
int n, p[N], v[N], diff[N];
vi g[N];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n;
    rep(i, 1, n)
    {
        int x;
        cin >> x;
        diff[x]++;
        g[x].eb(i);
    }
    rep(i, 1, n) cin >> p[i];
    rep(i, 1, n) cin >> v[i];
    int mn = N, mni = 0;
    rep(i, 1, n)
    {
        diff[i] += diff[i - 1] - 1;
        if (mn > diff[i]) mn = diff[i], mni = i;
    }
    int ans = 0;
    set<int> power;
    rep(i, mni + 1, mni + n)
    {
        int pos = (i > n) ? i - n : i;
        for (int s : g[pos]) power.insert(v[s]);
        auto it = power.lower_bound(p[pos]);
        if (it == power.end()) power.erase(power.begin());
        else ans++, power.erase(it);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 837 ms 45796 KB Output is correct
2 Correct 463 ms 44644 KB Output is correct
3 Correct 575 ms 52580 KB Output is correct
4 Correct 574 ms 53092 KB Output is correct
5 Correct 423 ms 32496 KB Output is correct
6 Correct 337 ms 32364 KB Output is correct
7 Correct 453 ms 36192 KB Output is correct
8 Correct 399 ms 34412 KB Output is correct
9 Correct 461 ms 37740 KB Output is correct
10 Correct 403 ms 33976 KB Output is correct