Problem p02695 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) { // for debug
  ll n = vec.size();
  cout << "------------------------------------\n";
  rep(i, n) cout << i << " " << vec.at(i) << "\n";
  cout << "------------------------------------\n";
}

void pr2d(vector<vector<ll>> vec) { // for debug
  ll h = vec.size();
  ll w = vec.at(0).size();
  cout << "------------------------------------\n";
  rep(i, h) {
    rep(j, w) { cout << vec.at(i).at(j) << " "; }
    cout << "\n";
  }
  cout << "------------------------------------\n";
}

int main() {
  ll n, m, q;
  cin >> n >> m >> q;
  vector<vector<vector<ll>>> v(
      m + 1, vector<vector<ll>>(
                 0, vector<ll>(0))); // v[a][b][c] 長さaの数列たちを入れる。

  for (int i = 1; i <= m; i++) {
    v.at(1).push_back({i});
  }

  for (int i = 1; i < n; i++) {
    for (auto a : v.at(i)) { // 長さiの数列を全部持ってくる
      ll am = a.back();
      for (int b = am; b <= m; b++) {
        auto c = a; // cに持ってきた数列をコピーする
        c.emplace_back(b);
        v.at(i + 1).emplace_back(c);
      }
    }
  }

  vector<vector<ll>> query(q, vector<ll>(4, 0));

  rep(i, q) {
    rep(j, 4) { cin >> query[i][j]; }
  }

  ll ans = 0;
  for (auto a : v.at(n)) {
    ll aans = 0;
    rep(i, q) {
      if (a.at(query[i][1] - 1) - a.at(query[i][0] - 1) == query[i][2])
        aans += query[i][3];
    }
    ans = max(ans, aans);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec) { // for debug
  ll n = vec.size();
  cout << "------------------------------------\n";
  rep(i, n) cout << i << " " << vec.at(i) << "\n";
  cout << "------------------------------------\n";
}

void pr2d(vector<vector<ll>> vec) { // for debug
  ll h = vec.size();
  ll w = vec.at(0).size();
  cout << "------------------------------------\n";
  rep(i, h) {
    rep(j, w) { cout << vec.at(i).at(j) << " "; }
    cout << "\n";
  }
  cout << "------------------------------------\n";
}

int main() {
  ll n, m, q;
  cin >> n >> m >> q;
  vector<vector<vector<ll>>> v(
      n + 1, vector<vector<ll>>(
                 0, vector<ll>(0))); // v[a][b][c] 長さaの数列たちを入れる。

  for (int i = 1; i <= m; i++) {
    v.at(1).push_back({i});
  }

  for (int i = 1; i < n; i++) {
    for (auto a : v.at(i)) { // 長さiの数列を全部持ってくる
      ll am = a.back();
      for (int b = am; b <= m; b++) {
        auto c = a; // cに持ってきた数列をコピーする
        c.emplace_back(b);
        v.at(i + 1).emplace_back(c);
      }
    }
  }

  vector<vector<ll>> query(q, vector<ll>(4, 0));

  rep(i, q) {
    rep(j, 4) { cin >> query[i][j]; }
  }

  ll ans = 0;
  for (auto a : v.at(n)) {
    ll aans = 0;
    rep(i, q) {
      if (a.at(query[i][1] - 1) - a.at(query[i][0] - 1) == query[i][2])
        aans += query[i][3];
    }
    ans = max(ans, aans);
  }
  cout << ans << endl;
}