Problem:
B - ライオン
あなたは動物園に来てライオンを見ている。
この動物園には
n
個のライオンのオリがある。
あなたはライオンが全部で何頭いるのか知りたくなったのだが、
一人で数えるのは大変だ。
そこで近くにいた動物園の来園者
m
人に協力してもらうことにした。
ライオンのオリは、それぞれ
1
番から
n
番までの数字がついており、
順番に並んでいる。
一つのオリには
0
頭以上
x
頭以下のライオンがいる。
m
人の来園者で
i
番目の人
(1 ≤ i ≤ m)
には
l_i
番から
r_i
番までの
両端を含むすべてのオリのライオンの数の総和を数えてもらった。
この情報を元に、
1
から
n
各オリの中のライオンの数を求めることにした。
入力形式
入力は以下の形式で与えられる
n
x
m
l_1
r_1
s_1
...
l_m
r_m
s_m
1行目は3つの整数
n
x
m
で、
それぞれオリの数、一つのオリの中のライオンの最大の数、
数えるのに協力した人の数である。
2行目から続く
m
行は各行3つの整数で、
それぞれ
i
番目の人が数えた結果
l_i
r_i
s_i
である。
l_i
番から
r_i
番までのオリのライオンを数えたら
合計
s_i
頭いたことを表している。
出力形式
数えてもらった結果が全て正しいとして、
1
から
n
の
各オリの中のライオンの数を空白区切りの
n
個の整数で出力せよ。
そのような答が複数あるときは、
ライオンの数の合計が最大になるものをどれでも良いので一つ出力せよ。
条件を満たすライオンの配置が一つもないときは
-1
を出力せよ。
制約
1 ≤ n ≤ 6
1 ≤ x ≤ 10
1 ≤ m ≤ 10
1 ≤ l_i ≤ r_i ≤ n
0 ≤ s_i ≤ 60
入力値はすべて整数である。
入出力例
入力例 1
3 5 1
1 2 5
出力例 1
2 3 5
その他"4 1 5"や"0 5 5"なども正しい出力である。
入力例 2
4 5 2
1 3 15
3 4 3
出力例 2
-1
条件を満たすライオンの配置が一つもないときは
-1
を出力せよ。

Submitted solutions:

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

void dfs(vector<int> v, vector<int> &L, vector<int> &R, vector<int> &S, int N,
         int M, int X, int &ans, vector<int> &ansvec) {
    if (v.size() == N) {
        vector<int> s(N + 10);
        for (int i = 0; i < N; i++) {
            s[i + 1] = s[i] + v[i];
        }
        bool flag = true;
        for (int i = 0; i < M; i++) {
            if (s[R[i]] - s[L[i]] != S[i]) {
                flag = false;
            }
        }
        if (flag) {
            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += v[i];
            }
            if (sum > ans) {
                ans = sum;
                ansvec.clear();
                for (int i = 0; i < N; i++) {
                    ansvec.push_back(v[i]);
                }
            }
            return;
        } else {
            return;
        }
    }
    for (int i = 0; i <= X; i++) {
        v.push_back(i);
        dfs(v, L, R, S, N, M, X, ans, ansvec);
        v.pop_back();
    }
}

int main() {
    int N, M, X;
    cin >> N >> X >> M;
    vector<int> L(M), R(M), S(M);
    for (int i = 0; i < M; i++) {
        cin >> L[i] >> R[i] >> S[i];
        L[i]--;
    }
    int ans = -2e9;
    vector<int> ansvec;
    dfs({}, L, R, S, N, M, X, ans, ansvec);
    if (ans == -2e9) {
        cout << -1 << endl;
    } else {
        cout << ansvec[0];
        for (int i = 1; i < N; i++) {
            cout << " " << ansvec[i];
        }
        cout << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3584
final_rank: 11

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

template < class T > vector< T >& operator++(vector< T >& a) { for(T& x : a) x++; return a; }
template < class T > vector< T >& operator--(vector< T >& a) { for(T& x : a) x--; return a; }
template < class T > vector< T >  operator++(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x++; return res; }
template < class T > vector< T >  operator--(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x--; return res; }

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int n = in(), x = in(), m = in();
    vector<tuple<int,int,int>> lrs(m);
    for(auto &[l, r, s] : lrs) l = in(), r = in(), s = in(), l--;

    int ma = -1;
    vector<int> argma;
    vector<int> A;
    auto dfs = [&](auto self, int i) -> void {
        if(i == n) {
            vector<int> Asum(n + 1, 0);
            for(int i : rep(n)) Asum[i + 1] += Asum[i] + A[i];
            bool ok = [&] {
                for(auto [l, r, s] : lrs) if(Asum[r] - Asum[l] != s) return false;
                return true;
            }();
            if(ok and ma < Asum[n]) {
                ma = Asum[n];
                argma = A;
            }
            return;
        }

        for(int a = 0; a <= x; a++) {
            A.push_back(a);
            self(self, i + 1);
            A.pop_back();
        }
        return;
    };

    dfs(dfs, 0);

    if(ma == -1) {
        print(ma);
    } else {
        print(argma);
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3452
final_rank: 8

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

int n, x, m;
int a[20];
int l[20], r[20], s[20];
vector<int> V;
int Ans;
bool F;

void dfs(vector<int> v) {
    if (v.size() == n) {
        int b[20] = {};
        for (int i = 0; i < v.size(); i++) {
            b[i + 1] = b[i] + v[i];
        }
        bool flg = true;
        for (int i = 0; i < m; i++) {
            if (b[r[i]] - b[l[i]] != s[i]) {
                flg = false;
            }
        }
        if (flg) {
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += v[i];
            }
            if (sum >= Ans) {
                Ans = sum;
                V.clear();
                for (int i = 0; i < n; i++) {
                    V.push_back(v[i]);
                }
            }
            return;
        } else {
            return;
        }
    }
    vector<int> vec = v;
    for (int i = 0; i <= x; i++) {
        vec.push_back(i);
        dfs(vec);
        vec.pop_back();
    }
}

void solve() {
    cin >> n >> x >> m;
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i] >> s[i];
        l[i]--;
    }
    dfs({});
    if (V.size()) {
        cout << V[0];
        for (int i = 1; i < V.size(); i++) {
            cout << " " << V[i];
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3432
final_rank: 7

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

int n, x, m;
int a[20];
int l[20], r[20], s[20];
vector<int> V;
int Ans;
bool F;

void dfs(vector<int> v) {
    if (v.size() == n) {
        int b[20] = {};
        for (int i = 0; i < v.size(); i++) {
            b[i + 1] = b[i] + v[i];
        }
        bool flg = true;
        for (int i = 0; i < m; i++) {
            if (b[r[i]] - b[l[i]] != s[i]) {
                flg = false;
            }
        }
        if (flg) {
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += v[i];
            }
            if (sum > Ans) {
                Ans = sum;
                V.clear();
                for (int i = 0; i < n; i++) {
                    V.push_back(v[i]);
                }
            }
            return;
        } else {
            return;
        }
    }
    vector<int> vec = v;
    for (int i = 0; i <= x; i++) {
        vec.push_back(i);
        dfs(vec);
        vec.pop_back();
    }
}

void solve() {
    cin >> n >> x >> m;
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i] >> s[i];
        l[i]--;
    }
    dfs({});
    if (V.size()) {
        cout << V[0];
        for (int i = 1; i < V.size(); i++) {
            cout << " " << V[i];
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    solve();
    return 0;
}
accuracy: 0.13043478260869565
time_ms: 40
memory_kb: 3432
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;

int main() {
  int n,x,m;
  cin >> n >> x >> m;
  vector<int> v (n,0);
  vector<vector<int>> s (m,vector<int> (3));
  vector<int> im (n+1,0);
  rep(i,m) {
    cin >> s[i][0] >> s[i][1] >> s[i][2];
  }
  vector<int> ans (n,-1);
  int mx = -1;
  int now = 0;
  while (now < pow(x+1,n)) {
    int q = now;
    rep(i,n) {
      v[i] = q%(x+1);
      q /= (x+1);
    }
    im[0] = 0;
    rep(i,n) {
      im[i+1] = im[i]+v[i];
    }
    rep(i,m) {
      if (im[s[i][1]]-im[s[i][0]-1] != s[i][2]) {
        break;
      }
      if (i == m-1) {
        int asd = 0;
        rep(e,n) {
          asd += v[e];
        }
        if (mx < asd) {
          mx = asd;
          rep(e,n) {
            ans[e] = v[e];
          }
        }
      }
    }
    now++;
  }
  if (ans[0] >= 0) {
    rep(e,n) {
          if (e == 0) {
            cout << ans[e];
          }
          else {
            cout << ' ' << ans[e];
          }
        }
        cout << endl;
        return 0;
  }
  cout << -1 << endl;
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3816
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;

int main() {
  int n,x,m;
  cin >> n >> x >> m;
  vector<int> v (n,0);
  vector<vector<int>> s (m,vector<int> (3));
  vector<int> im (n+1,0);
  rep(i,m) {
    cin >> s[i][0] >> s[i][1] >> s[i][2];
  }
  vector<int> ans (n,-1);
  int mx = 0;
  int now = 0;
  while (now < pow(x+1,n)) {
    int q = now;
    rep(i,n) {
      v[i] = q%(x+1);
      q /= (x+1);
    }
    im[0] = 0;
    rep(i,n) {
      im[i+1] = im[i]+v[i];
    }
    rep(i,m) {
      if (im[s[i][1]]-im[s[i][0]-1] != s[i][2]) {
        break;
      }
      if (i == m-1) {
        int asd = 0;
        rep(e,n) {
          asd += v[e];
        }
        if (mx < asd) {
          mx = asd;
          rep(e,n) {
            ans[e] = v[e];
          }
        }
      }
    }
    now++;
  }
  if (ans[0] >= 0) {
    rep(e,n) {
          if (e == 0) {
            cout << ans[e];
          }
          else {
            cout << ' ' << ans[e];
          }
        }
        cout << endl;
        return 0;
  }
  cout << -1 << endl;
  return 0;
}
accuracy: 0.13043478260869565
time_ms: 110
memory_kb: 3800
final_rank: 18

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

int n, x, m;
int a[20];
int b[20];
int l[20], r[20], s[20];
vector<int> V;
int Ans;
bool F;

void dfs(vector<int> v) {
    if (v.size() == n) {
        for (int i = 0; i < v.size(); i++) {
            b[i + 1] = b[i] + v[i];
        }
        bool flg = true;
        for (int i = 0; i < m; i++) {
            if (b[r[i]] - b[l[i]] != s[i]) {
                flg = false;
            }
        }
        if (flg) {
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += v[i];
            }
            if (sum > Ans) {
                Ans = sum;
                V.clear();
                for (int i = 0; i < n; i++) {
                    V.push_back(v[i]);
                }
            }
            return;
        } else {
            return;
        }
    }
    vector<int> vec = v;
    for (int i = 0; i <= x; i++) {
        vec.push_back(i);
        dfs(vec);
        vec.pop_back();
    }
}

void solve() {
    cin >> n >> x >> m;
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i] >> s[i];
        l[i]--;
    }
    dfs({});
    if (V.size()) {
        cout << V[0];
        for (int i = 1; i < V.size(); i++) {
            cout << " " << V[i];
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    solve();
    return 0;
}
accuracy: 0.13043478260869565
time_ms: 40
memory_kb: 3432
final_rank: 15

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

int n, x, m;
int a[20];
int b[20];
int l[20], r[20], s[20];
bool F;

void dfs(vector<int> v) {
    if (v.size() == n) {
        for (int i = 0; i < v.size(); i++) {
            b[i + 1] = b[i] + v[i];
        }
        bool flg = true;
        for (int i = 0; i < m; i++) {
            if (b[r[i]] - b[l[i]] != s[i]) {
                flg = false;
            }
        }
        if (flg && !F) {
            cout << v[0];
            for (int i = 1; i < v.size(); i++) {
                cout << " " << v[i];
            }
            cout << endl;
            F = true;
            return;
        } else {
            return;
        }
    }
    vector<int> vec = v;
    for (int i = 0; i <= x; i++) {
        vec.push_back(i);
        dfs(vec);
        vec.pop_back();
    }
}

void solve() {
    cin >> n >> x >> m;
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i] >> s[i];
        l[i]--;
    }
    dfs({});
    if (!F) {
        cout << -1 << endl;
    }
}

int main() {
    solve();
    return 0;
}
accuracy: 0.021739130434782608
time_ms: 50
memory_kb: 3364
final_rank: 20

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
    vi pw(7, 1); rep(i, 6) pw[i + 1] = pw[i] * 11;
    int N, X, M; cin >> N >> X >> M;
    vi L(M), R(M), S(M); rep(i, M) cin >> L[i] >> R[i] >> S[i];
    vi ans;
    int maxi = -1;
    rep(cmb, pw[N]){
        vi cand(N);
        bool flag = true;
        rep(i, N){
            cand[i] = (cmb / pw[i]) % 11;
            if (cand[i] > X) flag = false;
        }
        if (!flag) continue;
        rep(i, M){
            int cnt = 0;
            srep(j, L[i] - 1, R[i]) cnt += cand[j];
            if (cnt != S[i]){
                flag = false;
                break;
            }
        }
        if (flag){
            int sm = accumulate(all(cand), 0);
            if (sm > maxi){
                maxi = sm;
                ans = cand;
            }
        }
    }
    if (maxi == -1) cout << maxi << endl;
    else rep(i, N) cout << ans[i] << " \n"[i == N - 1];
}
accuracy: 1
time_ms: 100
memory_kb: 3436
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

vector ms(10,vector<int>(3));
int n,x,m;
vector<int> r(7),as(7,0),ansa(7);
int ans=-1;

void clc(int na){
  if(na==n+1){
    for(int i=0;i<m;i++){
      int sm=0;
      for(int j=ms[i][0];j<=ms[i][1];j++) sm+=as[j];
      if(sm!=ms[i][2]) return;
    }
    int sm=accumulate(as.begin(),as.end(),0);
    if(sm>ans){
      ans=sm;
      ansa=as;
     }
    return;
  }
  for(int i=0;i<=r[na];i++){
    as[na]=i;
    clc(na+1);
  }
  return;
} 

int main(){
  cin >> n >> x >> m;
  r.assign(n+1,x);
  vector<vector<int>> nx(n+1);
  for(int i=0;i<m;i++){
    cin >> ms[i][0] >> ms[i][1] >> ms[i][2];
    for(int j=ms[i][0];j<=ms[i][1];j++){ 
      r[j]=min(r[j],ms[i][2]);
    }
  }
  
  clc(1);
  if(ans==-1)  cout << ans << endl;
  else{
    for(int i=1;i<n;i++) cout << ansa[i] << " ";
    cout << ansa[n] << endl;
  }

}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 5

code_snippet: #include <vector>
#include <iostream>
using namespace std;

struct query {
	int l, r, s;
};

bool check(int N, int M, const vector<query>& qs, vector<int>& A) {
	for (query q: qs) {
		int s = 0;
		for (int i = q.l; i < q.r; i++) {
			s += A[i];
		}
		if (s != q.s) {
			return false;
		}
	}
	return true;
}

int main() {
	int N, X, M;
	cin >> N >> X >> M;
	vector<query> V(M);
	for (int i = 0; i < M; i++) {
		cin >> V[i].l >> V[i].r >> V[i].s;
		V[i].l--;
	}
	vector<int> ans;
	int best_sum = -1;
	vector<int> A(N, -1);
	auto dfs = [&](auto& self, int d) -> void {
		if (d == N) {
			if (check(N, M, V, A)) {
				int s = 0;
				for (int i = 0; i < N; i++) {
					s += A[i];
				}
				if (best_sum < s) {
					best_sum = s;
					ans = A;
				}
			}
			return;
		}
		for (int i = 0; i <= X; i++) {
			A[d] = i;
			self(self, d + 1);
		}
		A[d] = -1;
	};
	dfs(dfs, 0);
	if (best_sum != -1) {
		for (int i = 0; i < N; i++) {
			if (i != 0) {
				cout << ' ';
			}
			cout << ans[i];
		}
		cout << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3484
final_rank: 9

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,x,m; cin >> n >> x >> m;
    vector<int> l(m),r(m),s(m);
    for (int i = 0; i < m; ++i) {
        cin >> l[i] >> r[i] >> s[i];
        l[i]--;
    }
    vector<int> v(n);
    vector<int> sum(n+1);
    int mx = -1;
    vector<int> res;
    auto dfs = [&](auto dfs,int i)->void{
        if(i == n){
            for (int j = 0; j < m; ++j) {
                if(sum[r[j]]-sum[l[j]] != s[j]) return;
            }
//            for (int j = 0; j < n; ++j) {
//                if(j) cout << " ";
//                cout << v[j];
//            }
//            cout << endl;
//            exit(0);
            if(mx < sum[n]){
                mx = sum[n];
                res = v;
            }
            return;
        }
        for(int j=0;j<=x;j++){
            v[i] = j;
            sum[i+1] = sum[i]+v[i];
            dfs(dfs, i+1);
        }
    };
    dfs(dfs,0);
    if(mx != -1){
        for (int i = 0; i < n; ++i) {
            if(i) cout << " ";
            cout << res[i];
        }
        cout << endl;
    }
    else{
        cout << -1 << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 5

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
int dp[100];
int main(){
	int n,x,m,l[10],r[10],s[10];
	cin>>n>>x>>m;
	for(int i=0;i<m;i++)
		cin>>l[i]>>r[i]>>s[i],l[i]--;
	int mx=-1,ans;
	for(int S=0;S<pow(x+1,n);S++){
		int S2=S,arr[6];
		for(int i=0;i<n;i++){
			arr[i]=S2%(x+1);
			S2/=x+1;
		}
		bool ok=1;
		for(int i=0;i<m;i++){
			int sum=0;
			for(int j=l[i];j<r[i];j++)
				sum+=arr[j];
			if(sum!=s[i])
				ok=0;
		}
		if(ok){
			int sum=0;
			for(int i=0;i<n;i++)
				sum+=arr[i];
			if(sum>mx){
				mx=sum;
				ans=S;
			}
		}
	}
	if(mx==-1)
		cout<<-1<<endl,exit(0);
	int arr[6];
	for(int i=0;i<n;i++){
		arr[i]=ans%(x+1);
		ans/=x+1;
	}
	for(int i=0;i<n;i++)
		cout<<arr[i]<<(i+1==n?'\n':' ');
}
accuracy: 1
time_ms: 140
memory_kb: 3800
final_rank: 13

code_snippet: #include<iostream>
using namespace std;

int a[7], n, x, m, l[10], r[10], s[10], b[7] = {-1}, bsum = -1, c[7] = {};

void dfs(int i){
    if(i == n+1){
        int tmpsum = 0;
        for(int j = 1; j <= n; j++) c[j] = c[j-1]+a[j], tmpsum+=a[j];
        if(tmpsum <= bsum)  return;
        bool valid = true;
        for(int j = 0; j < m; j++){
            valid &= s[j]==c[r[j]]-c[l[j]-1];
        }
        if(valid){
            for(int j = 1; j <= n; j++) b[j] = a[j];
            bsum = tmpsum;
        }
        return;
    }
    for(int j = 0; j <= x; j++){
        a[i] = j;
        dfs(i+1);
    }
}

int main(){
    cin >> n >> x >> m;
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i] >> s[i];
    }
    dfs(1);
    if(bsum == -1){
        cout << -1 << endl;
    }else{
        for(int i = 1; i <= n; i++) cout << b[i] << " \n"[i==n];
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3112
final_rank: 1

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

int n, x, m, smax = -1;
vector<int> a, l, r, s, ans;

bool rec(int k){
    if(k == 0){
        bool ok = true;
        for(int i=0;i<m;i++){
            int sum = 0;
            for(int j=l[i]-1;j<r[i];j++){
                sum += a[j];
            }
            if(sum != s[i]) ok = false;
        }
        if(ok){
            int sum = 0;
            for(int i=0;i<n;i++) sum += a[i];
            if(sum > smax){
                ans = a;
            }
        }
        return ok;
    }
    else{
        bool ok = false;
        for(int i=0;i<=x;i++){
            a[k-1] = i;
            ok |= rec(k-1);
        }
        return ok;
    }
}

int main(){
    cin >> n >> x >> m;
    a.resize(n);
    l.resize(m);
    r.resize(m);
    s.resize(m);
    for(int i=0;i<m;i++){
        cin >> l[i] >> r[i] >> s[i];
    }
    if(rec(n)){
        for(int i=0;i<n;i++){
            cout << ans[i] << " \n"[i==n-1];
        }
    }
    else cout << -1 << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3172
final_rank: 4

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

int n, x, m;
vector<int> a, l, r, s;

bool rec(int k){
    if(k == 0){
        bool ok = true;
        for(int i=0;i<m;i++){
            int sum = 0;
            for(int j=l[i]-1;j<r[i];j++){
                sum += a[j];
            }
            if(sum != s[i]) ok = false;
        }
        if(ok){
            for(int i=0;i<n;i++){
                cout << a[i] << " \n"[i==n-1];
            }
        }
        return ok;
    }
    else{
        for(int i=0;i<=x;i++){
            a[k-1] = i;
            if(rec(k-1)) return true;
        }
    }
    return false;
}

int main(){
    cin >> n >> x >> m;
    a.resize(n);
    l.resize(m);
    r.resize(m);
    s.resize(m);
    for(int i=0;i<m;i++){
        cin >> l[i] >> r[i] >> s[i];
    }
    if(!rec(n)) cout << -1 << endl;
    return 0;
}
accuracy: 0.021739130434782608
time_ms: 40
memory_kb: 3024
final_rank: 19

code_snippet: #include<iostream>
using namespace std;

bool calcInc( int* a, int n, int x )
{
    bool judge = true;
    for( int i = 0; i < n; i++ )
        if( a[i] != x )
            judge = false;
    if( judge )
        return !judge;

    int i = n - 1;
    a[i]++;

    if( judge && a[n-1] == x + 1 )
        return false;

    while( i >= 0 && a[i] > x )
    {
        a[i] -= ( x + 1 );
        a[i-1]++;
        i--;
    }

    return !judge;
}

int main()
{
    int n, x, m;

    cin >> n >> x >> m;

    int a[n];
    for( int i = 0; i < n; i++ )
        a[i] = 0;

    int b[m][3];
    for( int i = 0; i < m; i++ )
        for( int j = 0; j < 3; j++ )
            cin >> b[i][j];

    int max = -1, res[n];
    do
    {
        bool judge = true;
        for( int i = 0; i < m; i++ )
        {
            int sum1 = 0;
            for( int j = b[i][0]; j <= b[i][1]; j++ )
                sum1 += a[j-1];

            if( sum1 != b[i][2] )
                judge = false;
        }

        int sum2 = 0;
        for( int i = 0; i < n; i++ )
            sum2 += a[i];

        if( judge && max < sum2 )
        {
            max = sum2;
            for( int i = 0; i < n; i++ )
                res[i] = a[i];
        }
    }
    while( calcInc( a, n, x ) );

    if( max == -1 )
        cout << -1 << endl;
    else
    {
        for( int i = 0; i < n - 1; i++ )
            cout << res[i] << " ";
        cout << res[n-1] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3116
final_rank: 3

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);


int n, x, m;
VI l, r, s;

VI vec, ans;
int asum = -1;

void check() {
	bool ret = true;
	rep(i, m) {
		int sum = 0;
		for (int j = l[i]; j <= r[i]; j++) { sum += vec[j]; }
		if (sum != s[i])ret = false;
	}

	if (ret) {
		int sum = accumulate(all(vec), 0);
		if (asum < sum) {
			ans = vec;
			asum = sum;
		}
	}
}

void dfs(int d) {
	if (d == n) {
		check();
	}
	else {
		rep(i, x + 1) {
			vec[d] = i;
			dfs(d + 1);
		}
	}
}

int main() {
	cin >> n >> x >> m;
	l = VI(m);
	r = VI(m);
	s = VI(m);
	rep(i, m) { cin >> l[i] >> r[i] >> s[i]; l[i]--; r[i]--; }

	vec = VI(n);
	rep(i, x + 1)dfs({});

	if (asum == -1) {
		Cout(-1);
	}
	else {
		rep(i, n)cout << ans[i] << (i == n - 1 ? "\n" : " ");
	}
}
accuracy: 1
time_ms: 750
memory_kb: 3156
final_rank: 14

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);

int n, x, m;
VI l, r, s;

VI vec, ans;
int asum = -1;

void check() {
	if (*max_element(all(vec)) != x) {
		return;
	}

	bool ret = true;
	rep(i, m) {
		int sum = 0;
		for (int j = l[i]; j <= r[i]; j++) { sum += vec[j]; }
		if (sum != s[i])ret = false;
	}

	if (ret) {
		int sum = accumulate(all(vec), 0);
		if (asum < sum) {
			ans = vec;
			asum = sum;
		}
	}
}

void dfs(int d) {
	if (d == n) {
		check();
	}
	else {
		rep(i, x + 1) {
			vec[d] = i;
			dfs(d + 1);
		}
	}
}

int main() {
	cin >> n >> x >> m;
	l = VI(m);
	r = VI(m);
	s = VI(m);
	rep(i, m) { cin >> l[i] >> r[i] >> s[i]; l[i]--; r[i]--; }

	vec = VI(n);
	rep(i, x + 1)dfs({});

	if (asum == -1) {
		Cout(-1);
	}
	else {
		rep(i, n)cout << ans[i] << (i == n - 1 ? "\n" : " ");
	}
}
accuracy: 0.13043478260869565
time_ms: 410
memory_kb: 3136
final_rank: 17

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

int n, x, m, ans = -1;
int ansls[6] = {0};
int cnt[7] = {0};
struct obser {
  int l;
  int r;
  int s;
};
vector<obser> ls;

void solve(int now);

int main() {
  cin >> n >> x >> m;
  for(int i = 0; i < m; ++i) {
    obser now;
    cin >> now.l >> now.r >> now.s;
    ls.push_back(now);
  }
  solve(0);
  if(ans == -1)
    cout << ans << endl;
  else {
    for(int i = 0; i < n; ++i) {
      cout << ansls[i];
      if(i != n - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

void solve(int now) {
  if(now == n) {
    bool ch = 1;
    for(int i = 0; i < m; ++i)
      if(ch) {
        int cntnum = 0;
        for(int j = ls[i].l - 1; j < ls[i].r; ++j)
          cntnum += cnt[j];
        if(cntnum != ls[i].s) ch = 0;
      }
    if(ch && ans < cnt[6]) {
      for(int i = 0; i < n; ++i) ansls[i] = cnt[i];
      ans = cnt[6];
    }
  }
  else {
    for(int i = 0; i <= x; ++i) {
      cnt[now] = i;
      cnt[6] += i;
      solve(now + 1);
      cnt[6] -= i;
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3152
final_rank: 2