Language: C++

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
 
int R, C;
map< pair<int,int>, int> in;
map< pair<int,int>, int> in2;
 
bool check_local(int y1, int x1, int y2, int x2){
  int a = (in.count(make_pair(y1,x1))>0)?in[make_pair(y1,x1)]:-1;
  int b = (in.count(make_pair(y1,x2))>0)?in[make_pair(y1,x2)]:-1;
  int c = (in.count(make_pair(y2,x1))>0)?in[make_pair(y2,x1)]:-1;
  int d = (in.count(make_pair(y2,x2))>0)?in[make_pair(y2,x2)]:-1;
  //cout << y << " " << x << endl;
  //cout << " " << a << " " << b << endl;
  //cout << " " << c << " " << d << endl;
  int minus = 0;
  if(a<0) minus++;
  if(b<0) minus++;
  if(c<0) minus++;
  if(d<0) minus++;
  if(minus == 0){
    if(a+d == b+c) return true;
    else return false;
  }
  if(minus == 1){
    if(a==-1){
      if(b+c>=d){
        in2[make_pair(y1,x1)] = b+c-d;
        return true;
      }
      else return false;
    }
    if(b==-1){
      if(a+d>=c){
        in2[make_pair(y1,x2)] = a+d-c;
        return true;
      }
      else return false;
    }
    if(c==-1){
      if(a+d>=b){
        in2[make_pair(y2,x1)] = a+d-b;
        return true;
      }
      else return false;
    }
    if(d==-1){
      if(b+c>=a){
        in2[make_pair(y2,x2)] = b+c-a;
        return true;
      }
      else return false;
    }
  }
  return true;
}



bool check2x2(){
  FOR(it,in){
    int y = (it->first).first;
    int x = (it->first).second;
    int a = it->second;
 
    //left-top
    if(y<R-1 && x<C-1){
      if(!check_local(y,x,y+1,x+1)) return false;
    }
    //right-top
    if(y<R-1 && x>0){
      if(!check_local(y,x-1,y+1,x)) return false;
    }
    //left-bottom
    if(y>0 && x<C-1){
      if(!check_local(y-1,x,y,x+1)) return false;
    }
    //right-bottom
    if(y>0 && x>0){
      if(!check_local(y-1,x-1,y,x)) return false;
    }
  }

  FOR(it1,in){
    FOR(it2,in){
      int y1 = (it1->first).first;
      int x1 = (it1->first).second;
      int y2 = (it2->first).first;
      int x2 = (it2->first).second;

      if(y<R-1 && x<C-1){
        if(!check_local(y1,x1,y2,x2)) return false;
      }
    }
  }
  return true;
}



int main(){
  ios::sync_with_stdio(false);
  int N;
  cin >> R >> C;
  cin >> N;
  rep(i,N){
    int r, c, a;
    cin >> r >> c >> a;
    r--;
    c--;
    in[make_pair(r,c)] = a;
  }
 
  while(true){
    if(!check2x2()){
      cout << "No" << endl;
      return 0;
    }
    
    if(in2.size() == 0) break;
    FOR(it,in2){
      in[it->first] = it->second;
    }
    in2.clear();
  }
  
  cout << "Yes" << endl;
  return 0;
}


Compiler output:
a.cc: In function 'bool check2x2()':
a.cc:110:10: error: 'y' was not declared in this scope; did you mean 'y2'?
  110 |       if(y<R-1 && x<C-1){
      |          ^
      |          y2
a.cc:110:19: error: 'x' was not declared in this scope; did you mean 'x2'?
  110 |       if(y<R-1 && x<C-1){
      |                   ^
      |                   x2