Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
   int n,st=0; 
   cin >> n;
   long long ans=0,cnt=0;
   set<int> s,t;
   vector<int> S,T;
   vector<int> x(n), y(n), z(n), p(n), q(n);
   for(int i=0; i<n; i++){
       cin >> x[i] >> y[i] >> z[i];
       if(!(s.count(x[i]))){
           S.push_back(x[i]);
           s.insert(x[i]);
        }
        if(!(t.count(y[i]))){
           T.push_back(y[i]);
           t.insert(y[i]);
        }
    }
    for(int i=0; i<n; i++){
        p[i]=min(abs(x[i]), abs(y[i]));
        ans+=z[i]*p[i];
    }
    cout << ans << endl;
    for(int i=0; i<n; i++){
        for(int j=0; j<S.size(); j++){
            cnt=0;
            for(int l=0; l<n; l++){
                q[l]=min(p[l],abs(x[l]-S[j]));
                cnt+=z[l]*q[l];
            }
            ans=min(ans,cnt);
            if(ans==cnt) st=S[j];
        }
        for(int j=0; j<T.size(); j++){
            cnt=0;
            for(int l=0; l<n; l++){
                q[l]=min(p[l],abs(y[l]-T[j]));
                cnt+=z[l]*q[l];
            }
            ans=min(ans,cnt);
            if(ans==cnt) st=T[j]+10000000;
        }
        cout << ans;
        if(st<9000000){
            for(int j=0; j<n; j++){
                p[j]=min(p[j],abs(x[j]-S[st]));
            }
            S.erase(st);
        }
        else{
            for(int j=0; j<n; j++){
                p[j]=min(p[j],abs(y[j]-T[st-10000000]));
            }
            T.erase(st-10000000);
        }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:20: error: no matching function for call to 'std::vector<int>::erase(int&)'
   51 |             S.erase(st);
      |             ~~~~~~~^~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided
a.cc:57:20: error: no matching function for call to 'std::vector<int>::erase(int)'
   57 |             T.erase(st-10000000);
      |             ~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided