Submission #1359522

#TimeUsernameProblemLanguageResultExecution timeMemory
1359522jumpMonsters (NOI25_monsters)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define int long long
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n,k;
  std::cin >> n >> k;
  std::vector<std::pair<int,int>> mon;
  for(int i=0;i<n;i++){
    int pos,hel;
    std::cin >> pos >> hel;
    mon.push_back({pos,hel});
  }
  std::sort(mon.begin(),mon.end());
  std::vector<std::pair<int,int>> mines;
  for(int i=0;i<k;i++){
    int pos;
    std::cin >> pos;
    mines.push_back({pos,0});
  }
  std::sort(mines.begin(),mines.end());
  int sum = 0;
  for(auto [cPos,cHp]:mon){
    std::pair<int,int> tar={cPos,0};
    int pos1 = std::min((int)(std::lower_bound(mines.begin(),mines.end(),tar)-mines.begin()),(int)(mines.size()-1));
    int pos2 = std::max(0,pos1-1);
    int cost1 = std::abs(cPos-mines[pos1].first)+1-mines[pos1].second;
    int cost2 = std::abs(cPos-mines[pos2].first)+1-mines[pos2].second;
    if(cost1<=cost2&&cost1<=cHp){
      mines[pos1].second=1;
      sum+=cost1;
    }
    else if(cost2<=cHp){
      mines[pos2].second=1;
      sum+=cost2;
    }
    else{
      sum+=cHp;
    }
  }
  std::cout << sum;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:26:24: error: no matching function for call to 'max(int, long long int)'
   26 |     int pos2 = std::max(0,pos1-1);
      |                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from Main.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
Main.cpp:26:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   26 |     int pos2 = std::max(0,pos1-1);
      |                ~~~~~~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
Main.cpp:26:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   26 |     int pos2 = std::max(0,pos1-1);
      |                ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
Main.cpp:26:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   26 |     int pos2 = std::max(0,pos1-1);
      |                ~~~~~~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
Main.cpp:26:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   26 |     int pos2 = std::max(0,pos1-1);
      |                ~~~~~~~~^~~~~~~~~~