제출 #1359523

#제출 시각아이디문제언어결과실행 시간메모리
1359523jumpMonsters (NOI25_monsters)C++20
100 / 100
67 ms9732 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((int)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;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…