RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
ICPC00073

D. Money for Nothing

Unrated 레이팅 미적용
난이도
5s
시간 제한
1024MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

In this problem you will be solving one of the most profound challenges of humans across the world since the beginning of time – how to make lots of money. You are a middleman in the widget market. Your job is to buy widgets from widget producer companies and sell them to widget consumer companies. Each widget consumer company has an open request for one widget per day, until some end date, and a price at which it is willing to buy the widgets. On the other hand, each widget producer company has a start date at which it can start delivering widgets and a price at which it will deliver each widget. Due to fair competition laws, you can sign a contract with only one producer company and only one c\(on- su\)mer company. You will buy widgets from the producer company, one per day, starting on the day it can start delivering, and ending on the date specified by the consumer company. On each of those days you earn the difference between the producer’s selling price and the consumer’s buying price. Your goal is to choose the consumer company and the producer company that will maximize your profits.

제약
입력 형식

The first line of input contains two integers \(m\) and \(n\) (\(1 \le m\), \(n \le 500\,000\)) denoting the number of producer and consumer companies in the market, respectively. It is followed by \(m\) lines, the \(i^{th}\) of which contains two integers \(pi\) and \(di\) (\(1 \le pi\), d\(i \le 10^{9}\)), the price (in dollars) at which the \(i^{th}\) producer sells one widget and the day on which the first widget will be available from this company. Then follow \(n\) lines, the \(j^{th}\) of which contains two integers \(qj\) and \(ej\) (\(1 \le qj\), e\(j \le 10^{9}\)), the price (in dollars) at which the \(j^{th}\) consumer is willing to buy widgets and the day immediately after the day on which the last widget has to be delivered to this company.

출력 형식

Display the maximum total number of dollars you can earn. If there is no way to sign contracts that gives you any profit, display 0.

예제 1
입력
2 2
1 3
2 1
3 5
7 2
출력
5
예제 2
입력
1 2
10 10
9 11
11 9
출력
0
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC World Finals 2017

평가 및 의견

D. Money for Nothing

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

D. Money for Nothing

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8