Language: C++

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll n,m;
  cin>>n>>m;
  vector<P> v(n);//まとめ
  vector<ll> vote(m,0);//政党ごと
  ll ina,inb;
  FOR(i,0,n){
    cin>>ina>>inb;
    vote[ina-1]++;
    v[i] = make_pair(inb,ina);
  }
  P max=make_pair(0,0);
  FOR(i,0,m){
    if(max.first<vote[i]) max=make_pair(vote[i],i+1);
  }
  FOR(i,0,n){
    if(v[i].second==max.second) v[i].first=v[i].first%2 + v[i].first/2;
  }
  sort(v.begin(),v.end());
  pair<int,int> sorti=make_pair(0,0);
  FOR(i,1,n){
    if(v[i].first==sorti.first&& sorti.second==max.second){
      v.erase(v.begin()+i);
      v.insert(v.begin()+sorti.second, sorti.first);
    }
    else{
      sorti = make_pair(v[i].first,i);
    }
  }
  reverse(v.begin()+sorti.second+1,v.end());

  FOR(i,0,n){
    cout<<v[i].first<<" party="<<v[i].second<<endl;
  }

  ll cost = 0;
  ll voteTo1 = vote[0];
  ll x=0;
  while(max.first>voteTo1){
    cost += v[x].first;
    if(v[x].second==max.second){
      cost += v[x].first;
      voteTo1++;
    }
    x++;
    voteTo1++;
    cout<<"cost="<<cost<<" x="<<x<<endl;
  }
  ll inst=x;
  if(max.first==voteTo1){
    while(x<n){
      if(v[inst].second!=max.second&&v[x].first<v[inst].first*2){
        cost+=v[x].first;
        break;
      }
      if(x==n-1){
        cost+=v[inst].first*2;
      }
      x++;
    }
  }
  if(max.second==1) cout<<0<<endl;
  else cout<<cost<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:36:15: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::insert(__gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >, int&)'
   36 |       v.insert(v.begin()+sorti.second, sorti.first);
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:2:
/usr/include/c++/14/bits/stl_vector.h:1484:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
 1484 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1484:9: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/vector:72:
/usr/include/c++/14/bits/vector.tcc:133:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; iterator = std::vector<std::pair<long long int, long long int> >::iterator; const_iterator = std::vector<std::pair<long long int, long long int> >::const_iterator; value_type = std::pair<long long int, long long int>]'
  133 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:135:57: note:   no known conversion for argument 2 from 'int' to 'const std::vector<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'}
  135 |     insert(const_iterator __position, const value_type& __x)
      |                                       ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1395:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; iterator = std::vector<std::pair<long long int, long long int> >::iterator; const_iterator = std::vector<std::pair<long long int, long long int> >::const_iterator; value_type = std::pair<long long int, long long int>]'
 1395 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1395:54: note:   no known conversion for argument 2 from 'int' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1395 |       insert(const_iterator __position, value_type&& __x)
      |                                         ~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1413:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; iterator = std::vector<std::pair<long long int, long long int> >::iterator; const_iterator = std::vector<std::pair<long long int, long long int> >::const_iterator]'
 1413 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1413:70: note:   no known conversion for argument 2 from 'int' to 'std::initializer_list<std::pair<long long int, long long int> >'
 1413 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1439:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; iterator = std::vector<std::pair<long long int, long long int> >::iterator; const_iterator = std::vector<std::pair<long long int, long long int> >::const_iterator; size_type = long unsigned int; value_type = std::pair<long long int, long long int>]'
 1439 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1439:7: note:   candidate expects 3 arguments, 2 provided