#include #include #include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; using vi = vector; using vb = vector; using vc = vector; using vvc = vector; using vvi = vector; using vvb = vector; using vpii = vector; using vpll = vector; using vll = vector; using vull = vector; using vvll = vector; using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; #define f first #define s second #define pb emplace_back #define rep(i, begin, end) for(auto i = (begin); i <= (end); ++i) #define repr(i, begin, end) for(auto i = (begin); i >= (end); --i) #define bend(X) X.begin(), X.end() #ifdef LOCAL #define deb(...) cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << endl #define say(...) cout << __VA_ARGS__ << endl #else #define deb(x) #define say(x) #define endl '\n' #endif constexpr int INF = 1e9+1e7; constexpr ll INFl = INF; constexpr ll INFll = 1e18+1e16; void print() { cout << '\n'; } template void print(T x, Args... args) { cout << x << ' '; print(args...); } template ostream& operator<<(ostream& os, pair x) { os << x.f << ' ' << x.s; return os; } template istream& operator>>(istream& is, pair& x) { is >> x.f >> x.s; return is; } template ostream& operator<<(basic_ostream& os, T x) { for(auto i : x) os << i << ' '; return os; } template istream& operator>>(istream& is, vector& x) { for(T& i : x) is >> i; return is; } template pair operator+(const pair& A, const pair& B) { return {A.f+B.f, A.s+B.s}; } template pair operator-(const pair& A, const pair& B) { return {A.f-B.f, A.s-B.s}; } template pair& operator+=(pair& A, const pair& B) { A.f += B.f; A.s += B.s; return A; } template pair& operator-=(pair& A, const pair& B) { A.f -= B.f; A.s -= B.s; return A; } template pair operator-(const pair& A) { return {-A.f, -A.s}; } template bool maxe(T1& A, const T2& B) { if(B>A) { A=B; return 1; } return 0; } template bool mine(T1& A, const T2& B) { if(B Nic operator<<(Nic, T) { return nic; } Nic operator<<(ostream&, Nic) { return nic; } ////////////////////////////////////////////////// constexpr int maxN = 16; int n; int W[maxN+1], sumW[1<> dni >> n; vector plecaki; vector aktualna_pojemnosc(n, 0); for (int i = 0; i < dni; i++) { int iledzis; cin >> iledzis; for (int j = 0; j < n; j++) { if (iledzis > j) { aktualna_pojemnosc[j] += 1; } else { if (aktualna_pojemnosc[j] > 0) { plecaki.push_back(aktualna_pojemnosc[j]); } aktualna_pojemnosc[j] = 0; } } } for (auto akt : aktualna_pojemnosc) { if (akt > 0) { plecaki.push_back(akt); } } sort(plecaki.begin(), plecaki.end(), greater()); vector najplecaki; for (int i = 0; i < min(n, (int)plecaki.size()); i++) W[i] = plecaki[i]; } auto solve() { ala(); rep (i, 0, n-1) cin >> T[i]; for (int b = 0; b < (1<> noOfTests; while(noOfTests --> 0) cout << solve() << '\n'; return 0; }