제출 #1367894

#제출 시각아이디문제언어결과실행 시간메모리
1367894mazeppaGrilled Bottle (KAISTRUN26SPRING_D)C++20
100 / 100
630 ms12340 KiB
#include <bits/stdc++.h>
#define endl '\n'
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using pii=pair<ll, ll>;

int N, M, A[202020], mn[202020], mx[202020];
pii B[202020];

struct cmp{
	bool operator()(pii a, pii b){
		return a.second<b.second;
	}
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>N>>M;
    for(int i=1; i<=N; i++) cin>>B[i].first>>B[i].second;
    for(int i=1; i<=M; i++) cin>>A[i];
    sort(B+1, B+N+1, greater<pii>());
    
    int l=0, r=M+1;
    ll ans=0;
    while(l+1<r){
    	int m=l+r>>1;
    	vector<int> v;
    	for(int i=1; i<=m; i++) v.push_back(A[i]);
    	sort(all(v), greater<int>());
    	priority_queue<pii, vector<pii>, cmp> pq;
    	int j=1;
    	ll t=0;
    	for(int i : v){
    		while(j<=N&&B[j].first>=i) pq.push(B[j++]);
    		if(pq.empty()){
    			t=-1;
    			break;
			}
			t+=pq.top().second;
			pq.pop();
		}
		ans=max(ans, t);
		if(t==-1) r=m;
		else l=m;
	}
	cout<<l<<' '<<ans<<endl;
	
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…