QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572403#9315. Rainbow Bracket SequencesubcripAC ✓82ms3996kbC++1724.6kb2024-09-18 14:19:302024-09-18 14:19:30

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 14:19:30]
  • 评测
  • 测评结果:AC
  • 用时:82ms
  • 内存:3996kb
  • [2024-09-18 14:19:30]
  • 提交

answer

// #pragma GCC target("popcnt,lzcnt,abm,bmi,bmi2")
#pragma GCC optimize("Ofast")
/************* This code requires C++17. ***************/

#include<bits/stdc++.h>
using namespace std;

/* macro helpers */
#define __NARGS(...) std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value
#define __DECOMPOSE_S(a, x) auto x = a;
#define __DECOMPOSE_N(a, ...) auto [__VA_ARGS__] = a;
constexpr void __() {}
#define __AS_PROCEDURE(...) __(); __VA_ARGS__; __()
#define __as_typeof(container) remove_reference<decltype(container)>::type

/* type aliases */
#if LONG_LONG_MAX != INT64_MAX
using ll = int64_t;
using ull = uint64_t;
#else
using ll = long long;
using ull = unsigned long long;
#endif
using int128 = __int128_t;
using uint128 = __uint128_t;
using ld = long double;
using pii = pair<int, int>;           using pil = pair<int, ll>;           using pid = pair<int, ld>;
using pli = pair<ll, int>;            using pll = pair<ll, ll>;            using pld = pair<ll, ld>;
using pdi = pair<ld, int>;            using pdl = pair<ld, ll>;            using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;    using tiil = tuple<int, int, ll>;    using tiid = tuple<int, int, ld>;
using tili = tuple<int, ll, int>;     using till = tuple<int, ll, ll>;     using tild = tuple<int, ll, ld>;
using tidi = tuple<int, ld, int>;     using tidl = tuple<int, ld, ll>;     using tidd = tuple<int, ld, ld>;
using tlii = tuple<ll, int, int>;     using tlil = tuple<ll, int, ll>;     using tlid = tuple<ll, int, ld>;
using tlli = tuple<ll, ll, int>;      using tlll = tuple<ll, ll, ll>;      using tlld = tuple<ll, ll, ld>;
using tldi = tuple<ll, ld, int>;      using tldl = tuple<ll, ld, ll>;      using tldd = tuple<ll, ld, ld>;
using tdii = tuple<ld, int, int>;     using tdil = tuple<ld, int, ll>;     using tdid = tuple<ld, int, ld>;
using tdli = tuple<ld, ll, int>;      using tdll = tuple<ld, ll, ll>;      using tdld = tuple<ld, ll, ld>;
using tddi = tuple<ld, ld, int>;      using tddl = tuple<ld, ld, ll>;      using tddd = tuple<ld, ld, ld>;
template <typename T> using max_heap = priority_queue<T>;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<>>;
template <typename T> using oi = ostream_iterator<T>;
template <typename T> using ii = istream_iterator<T>;

/* constants */
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll MDL = 1e9 + 7;
constexpr ll PRIME = 998'244'353;
constexpr ll MDL1 = 8784491;
constexpr ll MDL2 = PRIME;
constexpr int128 INT128_MAX = numeric_limits<int128>::max();
constexpr uint128 UINT128_MAX = numeric_limits<uint128>::max();
constexpr int128 INT128_MIN = numeric_limits<int128>::min();
constexpr uint128 UINT128_MIN = numeric_limits<uint128>::min();

/* random */

mt19937_64 rd(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());

/* bit-wise operations */
#define lowbit(x) ((x) & -(x))
#define popcount(x) (__builtin_popcountll(ll(x)))
#define parity(x) (__builtin_parityll(ll(x)))
#define msp(x) (63LL - __builtin_clzll(ll(x)))
#define lsp(x) (__builtin_ctzll(ll(x)))

/* arithmetic operations */
#define mod(x, y) ((((x) % (y)) + (y)) % (y))

/* fast pairs */
#define upair ull
#define umake(x, y) (ull(x) << 32 | (ull(y) & ((1ULL << 32) - 1)))
#define u1(p) ((p) >> 32)
#define u2(p) ((p) & ((1ULL << 32) - 1))
#define ult std::less<upair>
#define ugt std::greater<upair>

#define ipair ull
#define imake(x, y) (umake(x, y))
#define i1(p) (int(u1(ll(p))))
#define i2(p) (ll(u2(p) << 32) >> 32)
struct ilt {
    bool operator()(const ipair& a, const ipair& b) const {
        if (i1(a) == i1(b)) return i2(a) < i2(b);
        else return i1(a) < i1(b);
    }
};
struct igt {
    bool operator()(const ipair& a, const ipair& b) const {
        if (i1(a) == i1(b)) return i2(a) > i2(b);
        else return i1(a) > i1(b);
    }
};

/* conditions */
#define loop while (1)
#define if_or(var, val) if (!(var == val)) var = val; else
#define continue_or(var, val) __AS_PROCEDURE(if (var == val) continue; var = val;)
#define break_or(var, val) __AS_PROCEDURE(if (var == val) break; var = val;)

/* hash */
struct safe_hash {
    // https://codeforces.com/blog/entry/62393
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    template <typename T, typename U>
    size_t operator()(const pair<T, U>& a) const {
        auto hash1 = safe_hash()(a.first);
        auto hash2 = safe_hash()(a.second);
        if (hash1 != hash2) {
            return hash1 ^ hash2;
        }
        return hash1;
    }
};

uniform_int_distribution<mt19937::result_type> dist(PRIME);
const size_t __array_hash_b = 31, __array_hash_mdl1 = dist(rd), __array_hash_mdl2 = dist(rd);
struct array_hash {
    template <typename Sequence>
    size_t operator()(const Sequence& arr) const {
        size_t pw1 = 1, pw2 = 1;
        size_t res1 = 0, res2 = 0;
        for (auto&& x : arr) {
            res1 = (res1 + x * pw1) % __array_hash_mdl1;
            res2 = (res2 + x * pw2) % __array_hash_mdl2;
            pw1 = (pw1 * __array_hash_b) % __array_hash_mdl1;
            pw2 = (pw2 * __array_hash_b) % __array_hash_mdl2;
        }
        return res1 + res2;
    }
};

/* build data structures */
#define faster(um) __AS_PROCEDURE((um).reserve(1024); (um).max_load_factor(0.25);)
#define unordered_counter(from, to) __AS_PROCEDURE(unordered_map<__as_typeof(from), size_t, safe_hash> to; for (auto&& x : from) ++to[x];)
#define counter(from, to, cmp) __AS_PROCEDURE(map<__as_typeof(from), size_t, cmp> to; for (auto&& x : from) ++to[x];)
#define pa(a) __AS_PROCEDURE(__typeof(a) pa; pa.push_back({}); for (auto&&x : a) pa.push_back(pa.back() + x);)
#define sa(a) __AS_PROCEDURE(__typeof(a) sa(a.size() + 1); {int n = a.size(); for (int i = n - 1; i >= 0; --i) sa[i] = sa[i + 1] + a[i];};)
#define adj(ch, n) __AS_PROCEDURE(vector<vector<int>> ch((n) + 1);)
#define edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v), ch[v].push_back(u);)
#define edgew(ch, u, v, ...) __AS_PROCEDURE(ch[u].emplace_back(v, __VA_ARGS__), ch[v].emplace_back(u, __VA_ARGS__);)
#define Edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v);)
#define Edgew(ch, u, v, ...) __AS_PROCEDURE(ch[u].emplace_back(v, __VA_ARGS__);)
template <typename T, typename Iterator> pair<size_t, map<T, size_t>> discretize(Iterator __first, Iterator __last) {
    set<T> st(__first, __last);
    size_t N = 0;
    map<T, size_t> mp;
    for (auto&& x : st) mp[x] = ++N;
    return {N, mp};
}
template <typename T, typename Iterator> pair<size_t, unordered_map<T, size_t, safe_hash>> unordered_discretize(Iterator __first, Iterator __last) {
    set<T> st(__first, __last);
    size_t N = 0;
    unordered_map<T, size_t, safe_hash> mp;
    for (auto&& x : st) mp[x] = ++N;
    return {N, mp};
}

/* io */
#define untie __AS_PROCEDURE(ios_base::sync_with_stdio(0), cin.tie(NULL))
template<typename T, typename U> istream& operator>>(istream& in, pair<T, U>& p) {
    return in >> p.first >> p.second;
}
template<typename T, typename U> ostream& operator<<(ostream& out, const pair<T, U>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}
template<typename Char, typename Traits, typename Tuple, std::size_t... Index>
void print_tuple_impl(std::basic_ostream<Char, Traits>& os, const Tuple& t, std::index_sequence<Index...>) {
    using swallow = int[]; // guaranties left to right order
    (void)swallow { 0, (void(os << (Index == 0 ? "" : ", ") << std::get<Index>(t)), 0)... };
}
template<typename Char, typename Traits, typename... Args>
decltype(auto) operator<<(std::basic_ostream<Char, Traits>& os, const std::tuple<Args...>& t) {
    os << "{";
    print_tuple_impl(os, t, std::index_sequence_for<Args...>{});
    return os << "}";
}
template<typename T> ostream& operator<<(ostream& out, const vector<T>& vec) {
    for (auto&& i : vec) out << i << ' ';
    return out;
}
std::ostream& operator<<(std::ostream& dest, const int128& value) {
    // https://stackoverflow.com/a/25115163/23881100
    std::ostream::sentry s( dest );
    if ( s ) {
        uint128 tmp = value < 0 ? -value : value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        if ( value < 0 ) {
            -- d;
            *d = '-';
        }
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) {
            dest.setstate( std::ios_base::badbit );
        }
    }
    return dest;
}
template<typename T> void __read(T& x) { cin >> x; }
template<typename T, typename... U> void __read(T& x, U&... args) { cin >> x; __read(args...); }
#define read(type, ...) __AS_PROCEDURE(type __VA_ARGS__; __read(__VA_ARGS__);)
#define readvec(type, a, n) __AS_PROCEDURE(vector<type> a(n); for (auto& x : a) cin >> x;)
#define readvec1(type, a, n) __AS_PROCEDURE(vector<type> a((n) + 1); copy_n(ii<type>(cin), (n), a.begin() + 1);)
#define putvec(a) __AS_PROCEDURE(copy(a.begin(), a.end(), oi<__as_typeof(a)::value_type>(cout, " ")); cout << endl;)
#define putvec1(a) __AS_PROCEDURE(copy(a.begin() + 1, a.end(), oi<__as_typeof(a)::value_type>(cout, " ")); cout << endl;)
#define putvec_eol(a) __AS_PROCEDURE(copy(a.begin(), a.end(), oi<__as_typeof(a)::value_type>(cout, "\n"));)
#define putvec1_eol(a) __AS_PROCEDURE(copy(a.begin() + 1, a.end(), oi<__as_typeof(a)::value_type>(cout, "\n"));)
#define debug(x) __AS_PROCEDURE(cerr << #x" = " << (x) << endl;)
#define debugvec(a) __AS_PROCEDURE(cerr << #a" = "; for (auto&& x : a) cerr << x << ' '; cerr << endl;)
#define deb(...) debug(make_tuple(__VA_ARGS__))

/* pops */
#define poptop(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.top(); q.pop();)
#define popback(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.back(); q.pop_back();)
#define popfront(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.front();q.pop_front();)

/* math */
template <typename return_t>
return_t qpow(ll b, ll p) {
    if (b == 0 and p != 0) return 0;
    if (p == 0) return 1;
    return_t half = qpow<return_t>(b, p / 2);
    if (p % 2 == 1) return half * half * b;
    else return half * half;
}

#define comb(n, k) ((n) < 0 or (k) < 0 or (n) < (k) ? 0 : fact[n] / fact[k] / fact[(n) - (k)])
#define fastcomb(n, k) ((n) < 0 or (k) < 0 or (n) < (k) ? 0 : fact[n] * factrev[k] * factrev[(n) - (k)])

constexpr inline int lg2(ll x) { return x == 0 ? -1 : sizeof(ll) * 8 - 1 - __builtin_clzll(x); }

void __exgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  __exgcd(b, a % b, y, x);
  y -= a / b * x;
}

ll inverse(ll a, ll b) {
    ll x, y;
    __exgcd(a, b, x, y);
    return mod(x, b);
}

vector<tuple<int, int, ll>> decompose(ll x) {
    // return (factor, count, factor ** count)
    vector<tuple<int, int, ll>> res;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            int cnt = 0;
            ll pw = 1;
            while (x % i == 0) ++cnt, x /= i, pw *= i;
            res.emplace_back(i, cnt, pw);
        }
    }
    if (x != 1) {
        res.emplace_back(x, 1, x);
    }
    return res;
}

vector<pii> decompose_prime(int N) {
    // return (factor, count)
    vector<pii> result;
    for (int i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            int cnt = 0;
            while (N % i == 0) N /= i, ++cnt;
            result.emplace_back(i, cnt);
        }
    }
    if (N != 1) {
        result.emplace_back(N, 1);
    }
    return result;
}

/* string algorithms */
vector<int> calc_next(string t) {  // pi function of t
  int n = (int)t.length();
  vector<int> pi(n);
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && t[i] != t[j]) j = pi[j - 1];
    if (t[i] == t[j]) j++;
    pi[i] = j;
  }
  return pi;
}
vector<int> calc_z(string t) {  // z function of t
    int m = t.length();
    vector<int> z;
    z.push_back(m);
    pair<int, int> prev = {1, -1};
    for (int i = 1; i < m; ++i) {
        if (z[i - prev.first] + i <= prev.second) {
            z.push_back(z[i - prev.first]);
        } else {
            int j = max(i, prev.second + 1);
            while (j < m && t[j] == t[j - i]) ++j;
            z.push_back(j - i);
            prev = {i, j - 1};
        }
    }
    return z;
}
vector<int> kmp(string s, string t) {  // find all t in s
  string cur = t + '#' + s;
  int sz1 = s.size(), sz2 = t.size();
  vector<int> v;
  vector<int> lps = calc_next(cur);
  for (int i = sz2 + 1; i <= sz1 + sz2; i++) {
    if (lps[i] == sz2) v.push_back(i - 2 * sz2);
  }
  return v;
}
int period(string s) {  // find the length of shortest recurring period
    int n = s.length();
    auto z = calc_z(s);
    for (int i = 1; i <= n / 2; ++i) {
        if (n % i == 0 && z[i] == n - i) {
            return i;
        }
    }
    return n;
}

/* modular arithmetic */
template <ll mdl> struct MLL {
    ll val;
    MLL(ll v = 0) : val(mod(v, mdl)) {}
    MLL(const MLL<mdl>& other) : val(other.val) {}
    friend MLL operator+(const MLL& lhs, const MLL& rhs) { return mod(lhs.val + rhs.val, mdl); }
    friend MLL operator-(const MLL& lhs, const MLL& rhs) { return mod(lhs.val - rhs.val, mdl); }
    friend MLL operator*(const MLL& lhs, const MLL& rhs) { return mod(lhs.val * rhs.val, mdl); }
    friend MLL operator/(const MLL& lhs, const MLL& rhs) { return mod(lhs.val * mod(inverse(rhs.val, mdl), mdl), mdl); }
    friend MLL operator%(const MLL& lhs, const MLL& rhs) { return mod(lhs.val - (lhs / rhs).val, mdl); }
    friend bool operator==(const MLL& lhs, const MLL& rhs) { return lhs.val == rhs.val; }
    friend bool operator!=(const MLL& lhs, const MLL& rhs) { return lhs.val != rhs.val; }
    void operator+=(const MLL& rhs) { val = (*this + rhs).val; }
    void operator-=(const MLL& rhs) { val = (*this - rhs).val; }
    void operator*=(const MLL& rhs) { val = (*this * rhs).val; }
    void operator/=(const MLL& rhs) { val = (*this / rhs).val; }
    void operator%=(const MLL& rhs) { val = (*this % rhs).val; }
};

template <ll mdl>
ostream& operator<<(ostream& out, const MLL<mdl>& num) {
    return out << num.val;
}

template <ll mdl>
istream& operator>>(istream& in, MLL<mdl>& num) {
    return in >> num.val;
}

// miscancellous
template <typename T, typename U>
bool chmax(T& lhs, const U& rhs) {
    bool ret = lhs < rhs;
    if (ret) {
        lhs = rhs;
    }
    return ret;
}
template <typename T, typename U>
bool chmin(T& lhs, const U& rhs) {
    bool ret = lhs > rhs;
    if (ret) {
        lhs = rhs;
    }
    return ret;
}

#define functor(func) ([&](auto&&... val) \
noexcept(noexcept(func(std::forward<decltype(val)>(val)...))) -> decltype(auto) \
{return func(std::forward<decltype(val)>(val)...);})
#define expr(ret, ...) ([&] (__VA_ARGS__) { return (ret); })
template <typename Func, typename RandomIt> void sort_by_key(RandomIt first, RandomIt last, Func extractor) {
    std::sort(first, last, [&] (auto&& a, auto&& b) { return std::less<>()(extractor(a), extractor(b)); });
}
template <typename Func, typename RandomIt, typename Compare> void sort_by_key(RandomIt first, RandomIt last, Func extractor, Compare comp) {
    std::sort(first, last, [&] (auto&& a, auto&& b) { return comp(extractor(a), extractor(b)); });
}
template <typename T, typename U, typename Iterator_T, typename Iterator_U>
vector<pair<T, U>> zip(Iterator_T a_first, Iterator_T a_last, Iterator_U b_first, Iterator_U b_last) {
    vector<pair<T, U>> res;
    auto a_it = a_first;
    auto b_it = b_first;
    for (; not (a_it == a_last) and not (b_it == b_last); ++a_it, ++b_it) {
        res.emplace_back(*a_it, *b_it);
    }
    return res;
}
template <typename T, typename U, typename Iterator_T, typename Iterator_U>
vector<pair<T, U>> zip_n(Iterator_T a_first, Iterator_U b_first, size_t n) {
    vector<pair<T, U>> res;
    if (n > 0) {
        res.emplace_back(*a_first, *b_first);
        for (size_t i = 1; i != n; ++i) {
            res.emplace_back(*++a_first, *++b_first);
        }
    }
    return res;
}
template <typename T>
class ArithmeticIterator : bidirectional_iterator_tag {
public:
    using difference_type = ptrdiff_t;
    using value_type = T;
private:
    value_type value;
public:
    ArithmeticIterator(const T& value) : value(value) {}
    value_type operator*() const { return value; }
    ArithmeticIterator<T>& operator++() { ++value; return *this; }
    ArithmeticIterator<T>& operator--() { --value; return *this; }
    bool operator==(const ArithmeticIterator<T>& rhs) const { return value == rhs.value; }
};
template <typename T> vector<pair<int, T>> enumerate(const vector<T>& container) {
    return zip<int, T>(ArithmeticIterator<int>(0), ArithmeticIterator<int>(INT_MAX), container.begin(), container.end());
}
#define initarray(init, N) (__initarray<decay<decltype(init)>::type, (N)>(init))
namespace detail {
    template <typename T, std::size_t...Is>
    constexpr std::array<T, sizeof...(Is)>
    make_array(const T& value, std::index_sequence<Is...>) {
        return {{(static_cast<void>(Is), value)...}};
    }
}

template <typename T, std::size_t N>
constexpr std::array<T, N> __initarray(const T& value) {
    return detail::make_array(value, std::make_index_sequence<N>());
}
/*******************************************************/

// #define SINGLE_TEST_CASE
// #define DUMP_TEST_CASE 7219
// #define TOT_TEST_CASE 10000

void dump() {}

void dump_ignore() {}

void prep() {
}

struct mcmf {
    struct edge {
        int to;
        ll cap;
        ll flow;
        ll cost;
        int rev;
        int mark;
    };
    vector<vector<edge>> edges;
    vector<ll> dis;
    vector<bool> vis;
    ll ret;
    mcmf(int n) : edges(n + 1), dis(n + 1), vis(n + 1) {}
    void add_edge(int from, int to, ll cap, ll cost, int mark = 0, int mark_rev = 0) {
        edges[from].push_back({ to, cap, 0, cost, int(edges[to].size()), mark });
        edges[to].push_back({ from, 0, 0, -cost, int(edges[from].size() - 1), mark_rev });
    }
    bool sp(int s, int t) {
        dis.assign(edges.size(), INFLL);
        dis[s] = 0;
        int n = edges.size();
        int f = 1;
        while (f) {
            f = 0;
            for (int i = 0; i < n; ++i) {
                for (auto&& [to, cap, flow, cost, rev, mark] : edges[i]) {
                    if (cap > flow and dis[to] > dis[i] + cost) {
                        dis[to] = dis[i] + cost;
                        f = 1;
                    }
                }
            }
        }
        return dis[t] != INFLL;
    }
    ll dfs(int s, int t, ll cap) {
        if (vis[s]) {
            return 0;
        }
        vis[s] = 1;
        if (s == t) {
            return cap;
        }
        ll res = 0;
        int n = edges[s].size();
        for (int i = 0; i < n; ++i) {
            auto e = edges[s][i];
            if (e.cap > e.flow and dis[e.to] == dis[s] + e.cost) {
                ll nw = dfs(e.to, t, min(cap - res, e.cap - e.flow));
                edges[s][i].flow += nw;
                edges[e.to][e.rev].flow -= nw;
                res += nw;
                ret += nw * e.cost;
                if (res == cap) {
                    return res;
                }
            }
        }
        return res;
    }
    // returns: (flow, cost)
    pll run(int s, int t) {
        ll res = 0; ret = 0;
        while (sp(s, t)) {
            vis.assign(edges.size(), 0);
            ll curr = dfs(s, t, LLONG_MAX);
            res += curr;
        }
        return { res, ret };
    }
};

struct bounded_mcmf {
    int n, m, S, T;
    mcmf net;
    ll sum, pre;
    vector<ll> fl;
    vector<ll> init;
    vector<ll> costs;
    bounded_mcmf(int n, int m) : sum(0), pre(0), n(n), m(m), S(0), T(n + 1), net(n + 1), fl(m), init(n + 1), costs(m) {}
    // handle negative loop case
    void add_edge(int from, int to, ll low, ll high, ll cost, int edge_id = -1) {
        if (cost < 0) {
            __add_edge(from, to, high, high, cost, -1);
            __add_edge(to, from, 0, high - low, -cost, edge_id);
        } else {
            __add_edge(from, to, low, high, cost, edge_id);
        }
        if (edge_id != -1) {
            costs[edge_id] = cost;
            if (cost < 0) {
                fl[edge_id] += high;  // RealFlow = UpperBound - Flow
            } else {
                fl[edge_id] += low;   // RealFlow = LowerBound + Flow
            }
        }
    }
    void __add_edge(int from, int to, ll low, ll high, ll cost, int edge_id = -1) {
        net.add_edge(from, to, high - low, cost, edge_id, -1);
        init[to] += low, init[from] -= low;
        pre += low * cost;
    }
    void prep(int s, int t) {
        for (int i = 1; i <= n; ++i) {
            if (init[i] > 0) {
                net.add_edge(S, i, init[i], 0, -1, -1);
                sum += init[i];
            } else if (init[i] < 0) {
                net.add_edge(i, T, -init[i], 0, -1, -1);
            }
        }
        net.add_edge(t, s, INFLL, 0, -1, -1);
    }
    // min-cost max-flow
    optional<tuple<ll, ll, vector<ll>>> run_mcmf(int s, int t) {  // BUG: unchecked code
        prep(s, t);
        if (sum != net.run(S, T).first) {
            return nullopt;
        } else {
            auto [res_flow, res_cost] = net.run(s, t);
            for (int from = 1; from <= n; ++from) {
                for (auto&& [to, cap, flow, cost, rev, mark] : net.edges[from]) {
                    if (mark != -1) {
                        if (costs[mark] < 0) {
                            fl[mark] -= flow;
                        } else {
                            fl[mark] += flow;
                        }
                    }
                }
            }
            res_cost += pre;
            return {{res_flow, res_cost, fl}};
        }
    }
    // min-cost flow
    optional<tuple<ll, ll, vector<ll>>> run_mcf(int s, int t) {
        prep(s, t);
        auto [res_flow, res_cost] = net.run(S, T);
        res_cost += pre;
        if (sum != res_flow) {
            return nullopt;
        } else {
            for (int from = 1; from <= n; ++from) {
                for (auto&& [to, cap, flow, cost, rev, mark] : net.edges[from]) {
                    if (mark != -1) {
                        if (costs[mark] < 0) {
                            fl[mark] -= flow;
                        } else {
                            fl[mark] += flow;
                        }
                    }
                }
            }
            return {{res_flow, res_cost, fl}};
        }
    }
};

// __attribute__((target("popcnt")))
void solve() {
    read(int, n, m);
    readvec1(int, l, m);
    readvec1(int, c, 2 * n);
    readvec1(int, v, 2 * n);

    ll tot = accumulate(v.begin(), v.end(), ll(0));

    bounded_mcmf net(2 * n + m + 2, 2 * n);

    int s = 2 * n + m + 1, t = 2 * n + m + 2;
    for (int i = 1; i <= n; ++i) {
        net.add_edge(s, 2 * i, 1, 1, 0);
    }
    for (int i = 1; i < 2 * n; ++i) {
        net.add_edge(i, i + 1, 0, n, 0);
    }
    for (int i = 1; i <= 2 * n; ++i) {
        net.add_edge(i, 2 * n + c[i], 0, 1, v[i], i - 1);
    }

    vector<int> cnt(m + 1);
    for (int i = 1; i <= 2 * n; ++i) {
        cnt[c[i]] += 1;
    }
    for (int i = 1; i <= m; ++i) {
        if (cnt[i] - l[i] < 0) {
            cout << -1 << '\n';
            return;
        }
        net.add_edge(2 * n + i, t, 0, cnt[i] - l[i], 0);
    }

    auto res = net.run_mcf(s, t);
    if (res != nullopt) {
        cout << tot - get<1>(res.value()) << '\n';
    } else {
        cout << -1 << '\n';
    }
}

int main() {
#if __cplusplus < 201402L or defined(_MSC_VER) and not defined(__clang__)
    assert(false && "incompatible compiler variant detected.");
#endif
    untie;
    prep();
#ifdef SINGLE_TEST_CASE
    solve();
#else
    read(int, t);
    for (int i = 0; i < t; ++i) {
#ifdef DUMP_TEST_CASE
        if (t != (TOT_TEST_CASE)) {
            solve();
        } else if (i + 1 == (DUMP_TEST_CASE)) {
            dump();
        } else {
            dump_ignore();
        }
#else
        solve();
#endif
    }
#endif
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

2
3 2
1 2
1 2 2 2 1 2
3 1 4 2 2 1
3 2
2 2
1 2 2 2 1 2
3 1 4 2 2 1

output:

9
-1

result:

ok 2 number(s): "9 -1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3848kb

input:

50
8 6
0 2 2 0 3 1
3 5 1 1 5 3 5 2 3 2 2 1 2 2 4 6
998133227 879226371 59632864 356493387 62611196 827258251 296576565 204244054 812713672 780267148 614679390 447700005 102067050 544546349 116002772 761999375
1 1
1
1 1
343766215 374461155
3 1
2
1 1 1 1 1 1
796323508 303640854 701432076 853325162 610...

output:

-1
343766215
2351080746
3426965219
-1
-1
1351561190
2539318868
1013080942
4656646546
-1
-1
2231197660
2719131728
3983627641
4712174168
-1
1046749330
6115214757
3920988203
-1
3902088946
-1
2566553992
5268471900
5977120748
7505501534
-1
5054275471
1467678317
883992368
1044562986
-1
4024634503
-1
14472...

result:

ok 50 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

25
20 4
0 0 0 1
2 2 2 2 4 4 4 1 2 2 2 1 3 4 1 3 4 4 3 1 3 2 1 4 2 2 4 1 2 2 3 3 4 1 3 1 4 1 2 1
569363376 821862673 89663213 862407789 442940149 823902948 903631686 838830270 645793571 397350060 806574247 373166844 448916252 435880456 969841293 998227951 276194969 654967687 396909705 696186514 16992...

output:

16418796680
10558213381
-1
1502390329
8534183652
13571062458
8007768610
12656453595
3378659874
8410746077
12352187024
5743130624
5952844559
2285684441
4242613506
836778846
4838639494
8586807028
8535185475
8089358175
5627473863
14399529671
-1
11483578919
4919631490

result:

ok 25 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3676kb

input:

83
6 5
1 0 1 1 0
2 4 4 5 3 2 4 5 3 3 3 3
597659626 649040970 33207011 223207847 960704874 418600362 658594226 417168695 767527655 622701955 867509363 235369723
6 2
0 0
1 1 2 2 2 2 1 1 1 2 2 1
405752009 976807343 267881918 26193206 947664189 555835767 587219021 231445627 755417826 541362608 846129246...

output:

-1
4518989634
3550182642
4529809699
4042429510
4145000717
-1
3635082691
-1
-1
3476472607
3732904849
3631909633
4479534795
3586223781
3380039505
2946284506
3615784040
-1
-1
-1
4940773463
3195952843
4073152216
4177883697
3398540362
3578975642
4308395607
-1
3078447178
3069102942
3135294474
5256676097
-...

result:

ok 83 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 3872kb

input:

71
7 4
0 1 0 4
3 4 1 1 4 4 2 4 1 1 1 4 4 4
580852652 638740575 585501313 439482552 637837864 335796176 447934224 259084035 778210267 469729886 908657968 750731414 508195022 701461051
7 6
0 1 1 0 0 1
3 2 4 3 5 3 1 1 5 4 3 1 6 1
198076752 601490845 123074777 392892100 148645775 938575995 355185760 558...

output:

4300550873
4711297430
-1
4468072610
4652801753
4661069155
5134971483
4367382968
4983190626
3065242360
-1
-1
4834379200
4355918462
-1
3592789392
3058869770
-1
3825913893
-1
4785350296
-1
4759459279
5342744097
4716826205
4873131448
5329193547
4821943641
3777324532
4115469556
-1
-1
-1
5061832610
520025...

result:

ok 71 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 3680kb

input:

62
8 3
0 2 0
3 3 3 1 1 1 3 2 1 2 2 1 1 2 1 1
222368048 906033133 8623893 807375696 461796409 362923880 194114590 733391789 137574156 670510137 237249112 673135534 595041001 875171159 112263159 649035661
8 6
2 1 0 0 0 0
3 5 2 2 1 3 3 3 6 4 5 5 1 2 5 4
28938721 556768926 23366504 887715271 624732370 3...

output:

5349781905
4269103485
4384563617
5171071054
4895598910
4667548481
-1
4157414045
-1
3927911942
-1
5127481462
5534185037
6071114899
4515756162
5965926191
-1
5617252300
5920664214
5826871785
5730385164
5947153970
5426721265
5820040011
5677486289
5193366586
6129016249
5739984903
5993708705
5520537026
54...

result:

ok 62 numbers

Test #7:

score: 0
Accepted
time: 2ms
memory: 3648kb

input:

55
9 9
2 2 0 0 0 0 0 2 0
6 2 3 9 5 4 2 4 1 1 4 7 1 4 5 8 6 2
907208811 754008138 161288468 562810007 149992530 997421612 144383292 832081887 228097972 446662965 77258752 375836694 743196568 527846851 580675905 438791943 977960026 39388076
9 6
0 1 0 0 0 0
5 3 3 4 3 6 5 4 6 5 2 5 6 5 5 1 2 2
861149655...

output:

-1
5600105080
-1
7505123959
7048625501
4827971490
-1
7031642652
-1
6001013535
-1
-1
6353971413
5896906204
3896102243
6540293759
5621534278
6599175212
-1
6721932183
6965230904
5681597954
8167088460
5632185532
-1
4750725522
6285591217
6320310809
6388859035
4686377743
5728065266
5503485599
6260485694
6...

result:

ok 55 numbers

Test #8:

score: 0
Accepted
time: 2ms
memory: 3688kb

input:

50
10 8
0 0 1 0 0 0 1 0
1 6 7 7 2 2 1 1 3 1 1 3 7 5 4 1 8 4 7 2
535526356 404334728 653535984 998133227 879226371 59632864 356493387 62611196 827258251 296576565 204244054 812713672 780267148 614679390 447700005 102067050 544546349 116002772 761999375 546951131
10 5
0 0 1 1 0
4 5 5 3 5 1 3 3 5 1 1 5...

output:

7267674502
6912276073
-1
-1
8427372986
-1
7057744914
6452405474
7564223610
7193916415
-1
5496837745
6671753900
7137256654
6574886409
7690341704
7357840728
8164970807
7172570060
6778745196
7668051341
6936083804
7305907682
7631088969
5717910532
6156605721
6923807013
-1
8207034493
-1
7418567782
6923770...

result:

ok 50 numbers

Test #9:

score: 0
Accepted
time: 3ms
memory: 3640kb

input:

33
15 1
3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
985238289 459697693 970988548 370603489 160471107 36299429 908579552 62669495 649913003 478356148 805843616 136680216 158560673 261854484 857048420 32835236 430050478 327696352 417017537 857880465 568473106 750242567 865990206 869...

output:

11069294141
9757752433
10517453854
10675484732
9851733289
11571987501
10382709663
11006679388
9835650684
10482963923
10190220836
11857634113
-1
-1
10077553084
9896319722
11821564137
11828952526
9761971634
9940132164
-1
-1
9227926173
13037241524
11565236192
11800412693
12028054248
11502933189
9949512...

result:

ok 33 numbers

Test #10:

score: 0
Accepted
time: 3ms
memory: 3860kb

input:

25
20 20
3 0 0 1 0 0 0 0 0 3 0 0 1 2 0 1 0 2 2 4
12 19 17 19 14 5 16 6 6 20 13 2 14 7 19 16 17 7 13 16 9 6 5 16 13 13 9 9 8 6 10 11 20 7 4 12 16 13 11 9
654967687 396909705 696186514 169923749 8142639 81507010 67587218 966803487 991350519 551259762 962079443 918589 708293964 213990501 934701547 8468...

output:

-1
14023274173
12588200963
13988453624
15030243485
13076569052
-1
-1
13842307153
-1
12832546330
14189266584
16492323989
16163650514
14012035305
-1
-1
-1
13929001098
13862644942
-1
15246522629
-1
13299413733
-1

result:

ok 25 numbers

Test #11:

score: 0
Accepted
time: 45ms
memory: 3772kb

input:

5
100 15
3 5 8 6 7 7 5 3 2 6 5 3 11 4 8
8 13 6 13 2 3 1 8 15 12 13 14 10 12 4 4 8 8 9 2 15 3 4 10 8 5 2 5 11 11 2 13 10 7 12 11 4 2 9 4 15 5 15 13 9 6 7 6 2 12 6 1 6 13 9 7 2 2 11 11 10 1 3 12 8 7 2 13 2 5 3 13 5 11 5 2 3 1 14 7 11 5 11 2 14 2 14 6 4 6 3 8 14 4 8 3 14 10 7 8 3 6 3 10 4 15 1 7 7 15 7...

output:

68656287465
-1
73754164914
-1
66855643431

result:

ok 5 number(s): "68656287465 -1 73754164914 -1 66855643431"

Test #12:

score: 0
Accepted
time: 48ms
memory: 3944kb

input:

5
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...

output:

50180678758
50870704431
50681956474
50326825344
50082567443

result:

ok 5 number(s): "50180678758 50870704431 50681956474 50326825344 50082567443"

Test #13:

score: 0
Accepted
time: 50ms
memory: 3752kb

input:

5
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...

output:

50123043357
49894721224
49905903560
49800425951
50290453726

result:

ok 5 number(s): "50123043357 49894721224 49905903560 49800425951 50290453726"

Test #14:

score: 0
Accepted
time: 51ms
memory: 3816kb

input:

5
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...

output:

49737365905
49994413194
49341230808
50684500745
49793176608

result:

ok 5 number(s): "49737365905 49994413194 49341230808 50684500745 49793176608"

Test #15:

score: 0
Accepted
time: 53ms
memory: 3852kb

input:

5
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...

output:

50795295835
50683352809
50584109282
50191465853
50296052110

result:

ok 5 number(s): "50795295835 50683352809 50584109282 50191465853 50296052110"

Test #16:

score: 0
Accepted
time: 49ms
memory: 3964kb

input:

5
100 2
50 50
1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 ...

output:

77645975042
46932545455
75387972767
51593068896
75125789587

result:

ok 5 number(s): "77645975042 46932545455 75387972767 51593068896 75125789587"

Test #17:

score: 0
Accepted
time: 62ms
memory: 3768kb

input:

5
100 3
33 33 33
1 2 3 3 1 2 2 3 1 3 1 2 1 2 3 3 2 1 3 2 1 2 3 1 2 3 1 2 1 3 2 1 3 2 1 3 1 2 3 2 1 3 2 1 3 2 1 3 1 2 3 2 3 1 2 1 3 2 3 1 1 3 2 3 2 1 1 3 2 2 1 3 3 2 1 3 1 2 1 3 2 2 1 3 3 2 1 1 3 2 1 3 2 2 1 3 1 2 3 1 2 3 3 1 2 3 2 1 2 1 3 2 3 1 3 1 2 1 3 2 3 2 1 2 3 1 1 3 2 2 3 1 2 1 3 1 3 2 3 1 2 3...

output:

47569003992
78257813017
75649820149
78096608259
75801530445

result:

ok 5 number(s): "47569003992 78257813017 75649820149 78096608259 75801530445"

Test #18:

score: 0
Accepted
time: 34ms
memory: 3764kb

input:

5
100 4
25 25 25 25
4 2 1 3 2 1 3 4 2 3 1 4 3 4 1 2 1 2 4 3 4 3 1 2 4 1 3 2 3 1 4 2 2 3 1 4 3 1 2 4 3 4 2 1 1 2 3 4 2 1 4 3 1 4 2 3 2 3 4 1 1 4 2 3 1 3 2 4 2 3 1 4 2 1 3 4 1 3 2 4 4 1 2 3 3 1 4 2 2 4 3 1 3 4 2 1 1 2 3 4 1 4 3 2 1 3 2 4 3 4 1 2 4 3 2 1 2 4 3 1 3 4 2 1 3 1 2 4 2 3 1 4 2 1 4 3 2 3 4 1 ...

output:

49672641055
49254335827
72699420378
47419555908
78372663626

result:

ok 5 number(s): "49672641055 49254335827 72699420378 47419555908 78372663626"

Test #19:

score: 0
Accepted
time: 6ms
memory: 3712kb

input:

5
100 5
20 20 20 20 20
3 5 1 4 2 3 1 2 5 4 4 2 5 3 1 4 5 1 2 3 2 1 4 5 3 5 3 1 2 4 1 5 3 2 4 3 2 4 1 5 5 1 3 2 4 5 3 2 1 4 3 1 2 5 4 1 2 4 5 3 5 4 2 1 3 1 3 4 5 2 2 3 1 4 5 5 1 3 4 2 2 5 1 4 3 3 1 2 5 4 1 4 2 5 3 4 1 3 5 2 2 3 5 1 4 4 1 2 5 3 1 2 4 5 3 4 3 5 1 2 4 5 3 2 1 2 3 5 4 1 5 4 1 3 2 3 2 1 5...

output:

48894843279
51076411567
48760306674
49447706471
48343913563

result:

ok 5 number(s): "48894843279 51076411567 48760306674 49447706471 48343913563"

Test #20:

score: 0
Accepted
time: 50ms
memory: 3880kb

input:

5
100 8
12 12 12 12 12 12 12 12
2 5 4 1 3 8 7 6 4 5 6 2 8 1 3 7 6 2 8 5 4 1 3 7 3 1 2 7 6 8 5 4 4 2 5 1 3 8 6 7 1 7 2 6 3 4 8 5 4 5 1 8 2 3 6 7 7 2 6 3 4 1 8 5 3 1 4 5 7 2 8 6 8 5 4 2 3 6 1 7 6 8 2 5 7 3 1 4 5 3 1 2 4 8 6 7 2 8 1 5 4 3 7 6 5 4 8 2 7 6 1 3 2 8 4 5 1 6 3 7 7 5 4 6 3 1 2 8 1 5 7 6 2 8 ...

output:

49034013094
79760195311
75443719749
79485721453
48687130741

result:

ok 5 number(s): "49034013094 79760195311 75443719749 79485721453 48687130741"

Test #21:

score: 0
Accepted
time: 64ms
memory: 3768kb

input:

5
100 10
10 10 10 10 10 10 10 10 10 10
5 9 10 4 2 7 6 1 3 8 3 10 1 5 8 6 4 9 7 2 9 5 10 8 4 2 7 3 6 1 8 6 4 9 1 7 10 2 3 5 6 8 4 2 10 1 9 7 3 5 5 3 7 4 6 1 8 2 9 10 9 4 1 5 8 2 10 7 3 6 3 6 8 7 4 2 10 9 5 1 5 4 7 1 2 6 9 8 10 3 8 4 3 5 2 1 9 7 10 6 1 10 6 5 8 3 2 7 9 4 10 2 6 4 7 5 9 1 8 3 1 8 9 7 3...

output:

72266990307
75160196630
75786392195
51100642015
72406675868

result:

ok 5 number(s): "72266990307 75160196630 75786392195 51100642015 72406675868"

Test #22:

score: 0
Accepted
time: 37ms
memory: 3704kb

input:

5
100 20
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
4 14 2 1 6 7 20 16 5 9 15 12 3 19 11 18 17 13 8 10 12 7 17 9 2 18 1 13 5 15 4 11 14 20 16 8 10 3 6 19 8 15 5 17 20 2 7 6 11 18 10 9 4 19 3 14 1 13 16 12 2 15 1 16 3 12 7 11 9 5 17 4 18 10 14 19 20 8 6 13 8 7 3 11 1 4 17 14 16 10 5 19 15 6 13 20 12 9 2...

output:

75590848261
77965749483
53629845926
55468084725
51327701362

result:

ok 5 number(s): "75590848261 77965749483 53629845926 55468084725 51327701362"

Test #23:

score: 0
Accepted
time: 68ms
memory: 3720kb

input:

5
100 40
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
8 19 40 27 30 6 10 37 13 2 1 38 31 7 18 25 29 39 12 15 36 24 28 22 5 23 17 14 34 4 9 21 16 32 26 11 20 33 3 35 17 7 22 15 12 18 10 25 3 31 29 39 35 9 36 19 33 5 32 11 8 21 24 27 37 4 38 13 1 26 28 30 6 2 23 14 2...

output:

48878184304
75573488720
76691477336
71863733468
73787341148

result:

ok 5 number(s): "48878184304 75573488720 76691477336 71863733468 73787341148"

Test #24:

score: 0
Accepted
time: 26ms
memory: 3780kb

input:

5
100 50
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
10 12 29 1 9 24 31 37 47 38 39 35 34 41 40 28 18 36 6 3 33 25 17 23 27 48 7 30 49 46 11 26 22 45 14 43 20 15 44 13 5 50 2 42 16 8 19 21 32 4 7 43 11 27 49 3 39 30 32 2 45 44 19 16 48 23 22 26...

output:

49238394988
50909355695
71641314332
47808122112
44920424578

result:

ok 5 number(s): "49238394988 50909355695 71641314332 47808122112 44920424578"

Test #25:

score: 0
Accepted
time: 41ms
memory: 3780kb

input:

5
100 80
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
48 23 16 28 73 75 8 55 62 65 72 60 25 3 51 33 7 41 71 69 54 70 56 29 38 26 32 50 66 53 9 64 20 19 34 78 22 43 27 5 40 63 6 36 68 10...

output:

51385125328
48903005778
74512958112
50911917426
78315533852

result:

ok 5 number(s): "51385125328 48903005778 74512958112 50911917426 78315533852"

Test #26:

score: 0
Accepted
time: 59ms
memory: 3712kb

input:

5
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
87 39 16 33 73 41 100 18 9 60 37 54 38 78 70 76 50 15 98 28 82 69 92 56 66 71 10 1 11 13 3...

output:

47618474637
69591020911
78652954201
50221184599
75623555465

result:

ok 5 number(s): "47618474637 69591020911 78652954201 50221184599 75623555465"

Test #27:

score: 0
Accepted
time: 67ms
memory: 3764kb

input:

5
100 1
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

76394260602
72669834991
74118280075
74197964014
72397265305

result:

ok 5 number(s): "76394260602 72669834991 74118280075 74197964014 72397265305"

Test #28:

score: 0
Accepted
time: 69ms
memory: 3708kb

input:

5
100 2
50 50
1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 1 2 2 1 1 2 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 1 2 2 2 2 1 1 2 1 2 1 1 1 1 2 2 1 1 2 2 1 2 1 2 1 1 2 1 1 1 1 1 1 2 2 2 2 2 2 2 1 1 2 1 1 1 1 2 2 1 1 1 1 2 1 2 1 2 2 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ...

output:

75826470293
71495187228
71989101286
75949648590
77622238712

result:

ok 5 number(s): "75826470293 71495187228 71989101286 75949648590 77622238712"

Test #29:

score: 0
Accepted
time: 71ms
memory: 3992kb

input:

5
100 4
25 25 25 25
4 1 4 2 3 1 1 3 2 4 2 4 2 4 4 1 1 2 2 4 4 4 3 3 2 4 2 3 2 1 4 4 2 4 2 1 1 2 1 3 4 4 1 2 2 4 2 4 3 1 3 3 1 4 1 1 3 2 3 3 4 1 3 1 4 2 4 2 3 1 3 2 3 1 4 3 1 1 2 3 3 1 3 2 4 3 1 3 2 4 2 3 2 1 3 3 4 1 2 1 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ...

output:

70464212073
73777290829
71622352708
73868689626
72267452091

result:

ok 5 number(s): "70464212073 73777290829 71622352708 73868689626 72267452091"

Test #30:

score: 0
Accepted
time: 71ms
memory: 3800kb

input:

5
100 8
12 12 12 12 12 12 12 12
6 2 4 7 2 7 1 3 4 8 4 5 1 4 3 8 3 6 5 4 1 3 3 7 7 4 5 6 8 2 6 1 6 6 4 8 8 7 3 7 4 5 8 6 1 4 1 5 6 8 8 1 2 2 4 8 4 7 7 7 2 3 3 3 7 1 6 5 1 3 5 8 2 8 2 3 6 8 1 5 4 5 5 5 3 1 3 7 1 5 2 4 2 1 2 7 6 2 2 6 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 ...

output:

73476940493
76205812790
70702797816
76138514225
76882420555

result:

ok 5 number(s): "73476940493 76205812790 70702797816 76138514225 76882420555"

Test #31:

score: 0
Accepted
time: 70ms
memory: 3700kb

input:

5
100 15
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
11 6 14 10 1 3 3 1 9 2 1 4 10 15 11 15 2 2 8 2 12 8 1 13 5 3 12 8 1 7 15 7 15 1 4 14 6 14 5 12 8 12 3 9 11 6 7 4 8 7 15 7 4 2 10 11 15 4 6 5 2 7 6 8 10 10 3 13 2 5 13 7 4 5 6 3 9 6 13 3 9 10 8 5 1 12 10 12 14 14 14 13 11 9 11 9 5 13 9 4 11 12 13 14 15 1 2 3 4 5...

output:

73190981281
71201905229
72579618766
75440905056
72955154995

result:

ok 5 number(s): "73190981281 71201905229 72579618766 75440905056 72955154995"

Test #32:

score: 0
Accepted
time: 73ms
memory: 3996kb

input:

5
100 30
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
10 29 29 25 6 23 15 7 1 21 4 10 28 13 8 14 11 24 4 16 30 22 10 26 9 3 14 26 16 2 11 2 9 13 18 20 2 9 23 15 1 1 27 10 6 5 18 22 28 20 12 24 4 19 25 17 30 26 7 16 8 6 29 7 3 3 17 28 5 17 21 5 24 18 2 4 12 19 3 27 20 8 22 25 6 27 7 30...

output:

73096028775
73026146315
73514029327
70168548360
73659380260

result:

ok 5 number(s): "73096028775 73026146315 73514029327 70168548360 73659380260"

Test #33:

score: 0
Accepted
time: 82ms
memory: 3772kb

input:

5
100 70
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
16 12 62 41 23 69 25 33 7 29 7 10 30 1 55 21 2 59 19 8 47 37 52 24 17 39 18 12 22 36 35 21 8 5 2 20 9 60 16 15 25 65 4 27 11 27 20 66 50 51 58 29 54 34...

output:

73917993426
73921487263
75509937979
73793439011
72274525874

result:

ok 5 number(s): "73917993426 73921487263 75509937979 73793439011 72274525874"

Test #34:

score: 0
Accepted
time: 10ms
memory: 3648kb

input:

10
50 10
5 5 5 5 5 5 5 5 5 5
3 9 5 4 1 8 6 7 2 10 2 8 5 1 3 7 4 10 9 6 4 8 2 5 1 7 10 9 3 6 4 8 1 10 7 6 2 9 3 5 9 6 1 4 2 10 7 5 3 8 7 6 5 2 4 1 10 9 8 3 8 3 10 2 5 9 1 4 7 6 7 9 3 5 4 1 6 2 8 10 10 4 3 5 9 2 6 8 1 7 7 3 6 9 2 4 5 1 8 10
999786468 991017819 978242471 972908828 968198014 948206271 9...

output:

36645687065
22289873347
23540747136
21894415061
24129874880
36793077668
24547859169
23469583907
37014452010
36577845955

result:

ok 10 numbers

Test #35:

score: 0
Accepted
time: 18ms
memory: 3712kb

input:

10
50 10
5 5 5 5 5 5 5 5 5 5
10 7 3 4 6 4 3 10 9 8 2 4 5 10 7 5 6 2 8 1 9 1 9 4 10 2 8 8 10 3 6 5 8 7 4 7 5 5 1 7 1 2 9 6 3 2 1 3 9 6 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
668653931 934889979 895406125 182773719 699515250 24127686 12...

output:

39233999095
36163750866
37918784492
37954698973
34802455945
34249109215
33372228139
35443285892
35190281762
33944869935

result:

ok 10 numbers

Extra Test:

score: 0
Extra Test Passed