Language: C++

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*mod*/const int mod=1e9+7;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗 1*/ll llpow(ll x,ll n){ll ans=1,i;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*n乗 2*/ll modpow(ll x,ll n){ll ans=x,i,tmp=x,t1=1;i=1; while(i<n){if(i*2<n){ans*=ans;ans%=mod;i*=2;}else{t1=1;tmp=x;while(t1*2<n-i){tmp*=tmp;tmp%=mod;t1*=2;}ans*=tmp;ans%=mod;i+=t1;}}return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x){ans*=(x-i);ans%=mod;}return ans;}
/*逆元*/ll inv(ll x){return modpow(x,mod-2);}
/*nCr*/ll ncr(ll n,ll r){ll a=fact(n),b=modpow(fact(n-r),mod-2),c=modpow(fact(r),mod-2);ll ans=a*b;ans%=mod;ans*=c;ans%=mod;return ans;}
/*nPr*/ll npr(ll n,ll r){ll a=fact(n),b=modpow(fact(n-r),mod-2);return (a*b)%mod;}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
struct data{
 ll a;
 ll b;
 ll c;
 ll d;
 bool operator<(const data&right)const{
  return d==right.d?(a==right.a?(b==right.b?c>right.c:b>right.b):a>right.a):d>right.d;
 }
};
int main(){
 ll n,m,q;
 cin>>n>>m>>q;
 vector<data>t(q);
 ll w,x,y,z;
 rep(i,0,q){
  cin>>t.at(i).b>>t.at(i).a>>t.at(i).c>>t.at(i).d;
  t[i].a--;t[i].b--;
 }
 sort(all(t));
 
 ll num[n+10],score,k,ans=0;
 bool used[q+10];
 rep(i,0,q){//i個目の条件は必ず満たすように
 // cout<<"i: "<<i<<endl;
  rep(j,1,m+1){//t[i].aの値をjに設定する
   rep(k,0,n)num[k]=0;
   rep(k,0,q)used[k]=false;//初期化
   used[i]=true;
   if(j-t[i].c<=0)continue;
  // cout<<" j: "<<j<<endl;
   score=t[i].d;
   num[t[i].a]=j;
   num[t[i].b]=j-t[i].c; 
    
   ll cnt=0;
   while(cnt<10){
    cnt++;
    rep(k,0,q){
     if(used[k])continue;
     if(num[t[k].a]!=0&&num[t[k].b]==0){  
      ll tmp=num[t[k].a]-t[k].c;
      if(tmp<1)continue;
      num[t[k].b]=tmp;
      score+=t[k].d;
      used[k]=true;
     }
     else if(num[t[k].b]!=0&&num[t[k].a]==0){  
      ll tmp=num[t[k].b]+t[k].c;
      if(tmp>m)continue;
      num[t[k].a]=tmp;
      score+=t[k].d;
      used[k]=true;
     }
     else if(num[t[k].a]==0&&num[t[k].b]==0)continue;
     else if(num[t[k].a]-num[t[k].b]==t[k].c)score+=t[k].d,used[k]=true;
     else used[k]=true;
    // cout<<"  k: "<<k<<" score: "<<score<<" "<<num[t[k].b]<<" "<<num[t[k].a]<<" "<<used[k]<<endl;
    }
   }
   rep(k,0,q){
    if(used[k])continue;
    if(num[t[k].a]==0&&num[t[k].b]==0){
     score+=t[k].d;
    }
   // cout<<"  k: "<<k<<" score: "<<score<<endl;
   }
   ans=max(ans,score);
  }
 }
 pr(ans);
return 0;}

Compiler output:
a.cc: In function 'int main()':
a.cc:106:13: error: template argument 1 is invalid
  106 |  vector<data>t(q);
      |             ^
a.cc:106:13: error: template argument 2 is invalid
a.cc:109:10: error: request for member 'at' in 't', which is of non-class type 'int'
  109 |   cin>>t.at(i).b>>t.at(i).a>>t.at(i).c>>t.at(i).d;
      |          ^~
a.cc:109:21: error: request for member 'at' in 't', which is of non-class type 'int'
  109 |   cin>>t.at(i).b>>t.at(i).a>>t.at(i).c>>t.at(i).d;
      |                     ^~
a.cc:109:32: error: request for member 'at' in 't', which is of non-class type 'int'
  109 |   cin>>t.at(i).b>>t.at(i).a>>t.at(i).c>>t.at(i).d;
      |                                ^~
a.cc:109:43: error: request for member 'at' in 't', which is of non-class type 'int'
  109 |   cin>>t.at(i).b>>t.at(i).a>>t.at(i).c>>t.at(i).d;
      |                                           ^~
a.cc:110:4: error: invalid types 'int[long long int]' for array subscript
  110 |   t[i].a--;t[i].b--;
      |    ^
a.cc:110:13: error: invalid types 'int[long long int]' for array subscript
  110 |   t[i].a--;t[i].b--;
      |             ^
a.cc:35:18: error: request for member 'begin' in 't', which is of non-class type 'int'
   35 | #define all(a) a.begin(),a.end()
      |                  ^~~~~
a.cc:112:7: note: in expansion of macro 'all'
  112 |  sort(all(t));
      |       ^~~
a.cc:35:28: error: request for member 'end' in 't', which is of non-class type 'int'
   35 | #define all(a) a.begin(),a.end()
      |                            ^~~
a.cc:112:7: note: in expansion of macro 'all'
  112 |  sort(all(t));
      |       ^~~
a.cc:122:10: error: invalid types 'int[long long int]' for array subscript
  122 |    if(j-t[i].c<=0)continue;
      |          ^
a.cc:124:11: error: invalid types 'int[long long int]' for array subscript
  124 |    score=t[i].d;
      |           ^
a.cc:125:9: error: invalid types 'int[long long int]' for array subscript
  125 |    num[t[i].a]=j;
      |         ^
a.cc:126:9: error: invalid types 'int[long long int]' for array subscript
  126 |    num[t[i].b]=j-t[i].c;
      |         ^
a.cc:126:19: error: invalid types 'int[long long int]' for array subscript
  126 |    num[t[i].b]=j-t[i].c;
      |                   ^
a.cc:133:14: error: invalid types 'int[long long int]' for array subscript
  133 |      if(num[t[k].a]!=0&&num[t[k].b]==0){
      |              ^
a.cc:133:30: error: invalid types 'int[long long int]' for array subscript
  133 |      if(num[t[k].a]!=0&&num[t[k].b]==0){
      |                              ^
a.cc:134:19: error: invalid types 'int[long long int]' for array subscript
  134 |       ll tmp=num[t[k].a]-t[k].c;
      |                   ^
a.cc:134:27: error: invalid types 'int[long long int]' for array subscript
  134 |       ll tmp=num[t[k].a]-t[k].c;
      |                           ^
a.cc:136:12: error: invalid types 'int[long long int]' for array subscript
  136 |       num[t[k].b]=tmp;
      |            ^
a.cc:137:15: error: invalid types 'int[long long int]' for array subscript
  137 |       score+=t[k].d;
      |               ^
a.cc:140:19: error: invalid types 'int[long long int]' for array subscript
  140 |      else if(num[t[k].b]!=0&&num[t[k].a]==0){
      |                   ^
a.cc:140:35: error: invalid types 'int[long long int]' for array subscript
  140 |      else if(num[t[k].b]!=0&&num[t[k].a]==0){
      |                                   ^
a.cc:141:19: error: invalid types 'int[long long int]' for array subscript
  141 |       ll tmp=num[t[k].b]+t[k].c;
      |                   ^
a.cc:141:27: error: invalid types 'int[long long int]' for array subscript
  141 |       ll tmp=num[t[k].b]+t[k].c;
      |                           ^
a.cc:143:12: error: invalid types 'int[long long int]' for array subscript
  143 |       num[t[k].a]=tmp;
      |            ^
a.cc:144:15: error: invalid types 'int[long long int]' for array subscript
  144 |       score+=t[k].d;
      |               ^
a.cc:147:19: error: invalid types 'int[long long int]' for array subscript
  147 |      else if(num[t[k].a]==0&&num[t[k].b]==0)continue;
      |                   ^
a.cc:147:35: error: invalid types 'int[long long int]' for array subscript
  147 |      else if(num[t[k].a]==0&&num[t[k].b]==0)continue;
      |                                   ^
a.cc:148:19: error: invalid types 'int[long long int]' for array subscript
  148 |      else if(num[t[k].a]-num[t[k].b]==t[k].c)score+=t[k].d,used[k]=true;
      |                   ^
a.cc:148:31: error: invalid types 'int[long long int]' for array subscript
  148 |      else if(num[t[k].a]-num[t[k].b]==t[k].c)score+=t[k].d,used[k]=true;
      |                               ^
a.cc:148:40: error: invalid types 'int[long long int]' for array subscript
  148 |      else if(num[t[k].a]-num[t[k].b]==t[k].c)score+=t[k].d,used[k]=true;
      |                                        ^
a.cc:148:54: error: invalid types 'int[long long int]' for array subscript
  148 |      else if(num[t[k].a]-num[t[k].b]==t[k].c)score+=t[k].d,used[k]=true;
      |                                                      ^
a.cc:155:13: error: invalid types 'int[long long int]' for array subscript
  155 |     if(num[t[k].a]==0&&num[t[k].b]==0){
      |             ^
a.cc:155:29: error: invalid types 'int[long long int]' for array subscript
  155 |     if(num[t[k].a]==0&&num[t[k].b]==0){
      |                             ^
a.cc:156:14: error: invalid types 'int[long long int]' for array subscript
  156 |      score+=t[k].d;
      |              ^