제출 #1364813

#제출 시각아이디문제언어결과실행 시간메모리
1364813mon_de2738Grilled Bottle (KAISTRUN26SPRING_D)C++20
100 / 100
373 ms7660 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii=pair<int, int>;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
const int maxn=400055;
ll n,m,k;
 
pii p[maxn];
int F[maxn>>1];
int V[maxn>>1];
int A[maxn>>1];
 
ll chk(int ths) {
    priority_queue<int> pq;
    ll res=0;
    for (int i=0; i<m+n; i++) {
        auto[_,v]=p[i];
        if (v>0) pq.push(v);
        else if (v>=-ths){
            if (pq.empty()) return 0;
            res+=pq.top();
            pq.pop();
        }
    }
    return res;
}
 
int main() {
    fastio;
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        cin >> F[i] >> V[i];
        p[i-1]={F[i],V[i]};
    }
    for (int i=1; i<=m; i++) {
        cin >> A[i];
        p[n+i-1]={A[i], -i};
    }
    sort(p,p+n+m, greater<pii>());
    ll ans=0;
    int lo=0, hi=m;
    while (lo<hi) {
        int mid=(lo+hi+1)>>1;
        ll t=chk(mid);
        if (t) lo=mid,ans=t;
        else hi=mid-1;
    }
    cout << hi << ' ' << ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…