제출 #1348248

#제출 시각아이디문제언어결과실행 시간메모리
1348248almaarmudMonsters (NOI25_monsters)C++20
14 / 100
144 ms5108 KiB
/*
██████╗  █████╗ ███████╗██╗  ██╗██╗██████╗
██╔══██╗██╔══██╗██╔════╝██║  ██║██║██╔══██╗
██████╔╝███████║███████╗███████║██║██║   ██║
██╔══██╗██╔══██║╚════██║██╔══██║██║██║   ██║
██║  ██║██║  ██║███████║██║  ██║██║██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═╝╚═════╝
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define ld long double
#define str string
#define ch char
#define db double
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define Bob cout<<"Bob\n";
#define Alice cout<<"Alice\n";
#define ordered_set tree<pair<ll, ll>, null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update>
const ll MOD=1e9+7;
const ll INF = 10000000000;
void solve(){
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n),h(n);
    for(int i = 0;i<n;i++){
      cin>>v[i]>>h[i];
    }
    vector<ll>mina(k);
    for(int i = 0;i<k;i++){
      cin>>mina[i];
    }
    ll ans = 0;
    bool ok = false;
    bool flag = false;
    sort(all(mina));
    for(int i = 0;i<n;i++){
      ll alma = v[i];
      ll armud = h[i];
      ll mn = LLONG_MAX;
      auto it = lower_bound(all(mina),alma);
      auto it1 = upper_bound(all(mina),alma);
      ll kh=LLONG_MAX;
      ll wg=LLONG_MAX;
      if(it!=mina.end()){
        kh = abs(alma-*it);
      }
      if(it1!=mina.begin()){
        wg = abs(alma-*it1);
      }
      mn=min({kh,wg,armud});
      if(mn==armud)ans+=armud;
      else if(mn==kh){
        ans+=kh;
        ok = true;
      }
      else{
        ans+=wg;
        flag = true;
      }
    }
    if(ok){
      ans++;
    }
    if(flag){
      ans++;
    }
    cout<<ans;
}
signed main(){
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...