Language: C++

#include <cstdio>
#include <map>
#include <set>

using namespace std;

typedef pair<int,int> P;
typedef pair<P,int> PP;

int comp(const PP& a, const PP& b) {
  return a.first < b.first;
}

int R,C;
int N;
PP rc[100010];
map<int,int> rConstraints;
map<int,int> cConstraints;
int main() {
  scanf("%d%d%d", &R, &C, &N);
  for(int i=0;i<N;++i) {
    int x,y,z;
    scanf("%d%d%d", &x, &y, &z);--x;--y;
    rc[i]=PP(P(x,y),z);
  }
  rc[N]=PP(P(200000,200000),0);
  /*for(int i=0;i<N+1;++i) {
    printf("(%d,%d)", rc[i].first.first, rc[i].first.second);
  }*/
  sort(rc, rc+N, comp);
  bool OK=true;
  for(int i=0;i<N;++i) {
    P currentPos=rc[i].first;
    P right = P(currentPos.first,currentPos.second+1);
    PP found=*lower_bound(rc,rc+N,PP(right,0),comp);
    if (found.first == right) {
      int tc = currentPos.second;
      int tv = (found.second - rc[i].second);
      auto it=cConstraints.find(tc);
      if (it!=cConstraints.end() && cConstraints[tc]!=tv) {
        OK=false;
      } else {
        cConstraints.insert(make_pair(tc,tv));
      }
    }
    currentPos=rc[i].first;
    right = P(currentPos.first+1,currentPos.second);
    found=*lower_bound(rc,rc+N,PP(right,0),comp);
    if (found.first == right) {
      int tc = currentPos.first;
      int tv = (found.second - rc[i].second);
      auto it=rConstraints.find(tc);
      if (it!=rConstraints.end() && rConstraints[tc]!=tv) {
        OK=false;
      } else {
        rConstraints.insert(make_pair(tc,tv));
      }
    }
  }

  for(int i=0;i<N;++i) {
    P& currentPos=rc[i].first;
    if(rConstraints.find(currentPos.first)!=rConstraints.end()) {
      int v=rConstraints[currentPos.first];
      int nv = rc[i].second + v;
      if (nv <0) {
        OK = false;
      }
    }
    if(rConstraints.find(currentPos.first-1)!=rConstraints.end()) {
      int v=rConstraints[currentPos.first-1];
      int nv = rc[i].second - v;
      if (nv <0) {
        OK = false;
      }
    }
    if(cConstraints.find(currentPos.second)!=cConstraints.end()) {
      int v=cConstraints[currentPos.second];
      int nv = rc[i].second + v;
      if (nv <0) {
        OK = false;
      }
    }
    if(cConstraints.find(currentPos.second-1)!=cConstraints.end()) {
      int v=cConstraints[currentPos.second-1];
      int nv = rc[i].second - v;
      if (nv <0) {
        OK = false;
      }
    }
  }

  if (OK) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   30 |   sort(rc, rc+N, comp);
      |   ^~~~
      |   short
a.cc:35:26: error: no matching function for call to 'lower_bound(PP [100010], PP*, PP, int (&)(const PP&, const PP&))'
   35 |     PP found=*lower_bound(rc,rc+N,PP(right,0),comp);
      |               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_tree.h:63,
                 from /usr/include/c++/14/map:62,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note:   candidate expects 3 arguments, 4 provided
a.cc:48:23: error: no matching function for call to 'lower_bound(PP [100010], PP*, PP, int (&)(const PP&, const PP&))'
   48 |     found=*lower_bound(rc,rc+N,PP(right,0),comp);
      |            ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note: candidate: 'template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:5: note:   candidate expects 3 arguments, 4 provided