Language: C++


ll rec(int i, vector<int> &curr) {
    if(i == N) {
        ll e = 0;
        for(int j = 0; j < Q; j++) {
            if(curr[b[j] - 1] - curr[a[j] - 1] == c[j]) e += d[j];
        }
        return e;
    }
    
    vector<int> nxt = curr;
    ll ans = 0;
    for(int j = curr.back(); j <= M; j++) {
        nxt.push_back(j);
        ans = max(ans, rec(i + 1, nxt));
        nxt.pop_back();
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M >> Q;
    int tem = -1;
    for(int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        if(a[i] == 1 and b[i] == 2) {
            tem = i;
        }
    }
    vector<int> start(1, 1);
    cout << rec(1, start) << "\n";
    return 0;
}

/* don't forget to check:
   int overflow
   min/max cases (n = 1)
   printing index of sorted array
   limits for ans (start with inf)
   s = 'x' + s is linear! dont use it!
 */


Compiler output:
a.cc:2:1: error: 'll' does not name a type
    2 | ll rec(int i, vector<int> &curr) {
      | ^~
a.cc: In function 'int main()':
a.cc:22:5: error: 'ios' has not been declared
   22 |     ios::sync_with_stdio(false); cin.tie(NULL);
      |     ^~~
a.cc:22:34: error: 'cin' was not declared in this scope
   22 |     ios::sync_with_stdio(false); cin.tie(NULL);
      |                                  ^~~
a.cc:22:42: error: 'NULL' was not declared in this scope
   22 |     ios::sync_with_stdio(false); cin.tie(NULL);
      |                                          ^~~~
a.cc:1:1: note: 'NULL' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | 
a.cc:23:12: error: 'N' was not declared in this scope
   23 |     cin >> N >> M >> Q;
      |            ^
a.cc:23:17: error: 'M' was not declared in this scope
   23 |     cin >> N >> M >> Q;
      |                 ^
a.cc:23:22: error: 'Q' was not declared in this scope
   23 |     cin >> N >> M >> Q;
      |                      ^
a.cc:26:16: error: 'a' was not declared in this scope
   26 |         cin >> a[i] >> b[i] >> c[i] >> d[i];
      |                ^
a.cc:26:24: error: 'b' was not declared in this scope
   26 |         cin >> a[i] >> b[i] >> c[i] >> d[i];
      |                        ^
a.cc:26:32: error: 'c' was not declared in this scope
   26 |         cin >> a[i] >> b[i] >> c[i] >> d[i];
      |                                ^
a.cc:26:40: error: 'd' was not declared in this scope
   26 |         cin >> a[i] >> b[i] >> c[i] >> d[i];
      |                                        ^
a.cc:31:5: error: 'vector' was not declared in this scope
   31 |     vector<int> start(1, 1);
      |     ^~~~~~
a.cc:31:12: error: expected primary-expression before 'int'
   31 |     vector<int> start(1, 1);
      |            ^~~
a.cc:32:5: error: 'cout' was not declared in this scope
   32 |     cout << rec(1, start) << "\n";
      |     ^~~~
a.cc:32:20: error: 'start' was not declared in this scope
   32 |     cout << rec(1, start) << "\n";
      |                    ^~~~~
a.cc:32:13: error: 'rec' was not declared in this scope
   32 |     cout << rec(1, start) << "\n";
      |             ^~~