Language: C++

#include <iostream>
#include <string>
using namespace std;
int a_list[200000];
int main(){
  int n, q, a0, b;
  cin >> n;
  cin >> q >> a >> b;
  a_list[0] = a
  min_x = a;
  max_x = a;
  min = b;
  
  for( int i=1; i< n; i++){
    cin >> q;
    if (q == 1){
      cin >> _a >> _b;
      a_list[i] = _a;
      b += _b;
      min;
	  int min_a_sub = abs(min_x - _a);
      int max_a_sub = abs(max_x - _a);
      int a_cand, min_cand1;
      int min_cand2 = b;
           
	  if( min_a_sub < max_a_sub ){
      	min_cand_1 = min + _b + min_a_sub;
        a_cand = min_x;
      }
      else{
        min_cand_1 = min + _b + max_a_sub;
        a_cand = max_x;
      }
 
      for (int j=0; j < i; j++){
	      min_cand_2 += abs(a_list[j] - a_list[i]);
      }
      
      if (min_cand_1 < min_cand_2){
          min = min_cand_1;
          min_x = a_cand;
          max_x = a_cand;
      }
      
      else if (min_cand_1 == min_cand_2){
      	  min = min_cand_1;
      	  if (_a < a_cand){
            min_x = _a;
            max_x = a_cand;
          }
          else if (_a > a_cand) {
          	min_x = a_cand;
            max_x = _a;
          }
          else {
			min_x = _a;
            max_x = _a;
          }
      }
      
      else ( min_cand_2 < min_cand_1){
          min = min_cand_2;
          min_x = _a;
          max_x = _a;
     }
     
     else{
	     if (min_x == max_x){
    	 	cout << min << endl;
	     }
         else{
         	cout << min_x << endl;
         }
     }
   }  
}
 


Compiler output:
a.cc: In function 'int main()':
a.cc:8:15: error: 'a' was not declared in this scope
    8 |   cin >> q >> a >> b;
      |               ^
a.cc:11:3: error: 'max_x' was not declared in this scope
   11 |   max_x = a;
      |   ^~~~~
a.cc:12:9: error: overloaded function with no contextual type information
   12 |   min = b;
      |         ^
a.cc:17:14: error: '_a' was not declared in this scope
   17 |       cin >> _a >> _b;
      |              ^~
a.cc:17:20: error: '_b' was not declared in this scope; did you mean 'b'?
   17 |       cin >> _a >> _b;
      |                    ^~
      |                    b
a.cc:20:10: error: statement cannot resolve address of overloaded function
   20 |       min;
      |          ^
a.cc:21:31: error: 'min_x' was not declared in this scope
   21 |           int min_a_sub = abs(min_x - _a);
      |                               ^~~~~
a.cc:27:9: error: 'min_cand_1' was not declared in this scope; did you mean 'min_cand1'?
   27 |         min_cand_1 = min + _b + min_a_sub;
      |         ^~~~~~~~~~
      |         min_cand1
a.cc:31:9: error: 'min_cand_1' was not declared in this scope; did you mean 'min_cand1'?
   31 |         min_cand_1 = min + _b + max_a_sub;
      |         ^~~~~~~~~~
      |         min_cand1
a.cc:36:15: error: 'min_cand_2' was not declared in this scope; did you mean 'min_cand2'?
   36 |               min_cand_2 += abs(a_list[j] - a_list[i]);
      |               ^~~~~~~~~~
      |               min_cand2
a.cc:39:11: error: 'min_cand_1' was not declared in this scope; did you mean 'min_cand1'?
   39 |       if (min_cand_1 < min_cand_2){
      |           ^~~~~~~~~~
      |           min_cand1
a.cc:39:24: error: 'min_cand_2' was not declared in this scope; did you mean 'min_cand2'?
   39 |       if (min_cand_1 < min_cand_2){
      |                        ^~~~~~~~~~
      |                        min_cand2
a.cc:67:6: error: expected '}' before 'else'
   67 |      else{
      |      ^~~~
a.cc:16:16: note: to match this '{'
   16 |     if (q == 1){
      |                ^
a.cc:68:18: error: 'min_x' was not declared in this scope
   68 |              if (min_x == max_x){
      |                  ^~~~~
a.cc:69:22: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and '<unresolved overloaded function type>')
   69 |                 cout << min << endl;
      |                 ~~~~~^~~~~~
In file included from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::ios_base& (*)(std::ios_base&)'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  174 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long int'
  174 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  178 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long unsigned int'
  178 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  182 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'bool'
  182 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short int'
   97 |     operator<<(short __n)
      |                ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  189 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short unsigned int'
  189 |       operator<<(unsigned short __n)
      |                  ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
  110 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'int'
  111 |     operator<<(int __n)
      |                ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  200 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'unsigned int'
  200 |       operator<<(unsigned int __n)
      |                  ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  211 |       operator<<(long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long int'
  211 |       operator<<(long long __n)
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  215 |       operator<<(unsigned long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long unsigned int'
  215 |       operator<<(unsigned long long __n)
      |                  ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  231 |       operator<<(double __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'double'
  231 |       operator<<(double __f)
      |