48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#include <algorithm>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
int main() {
|
|
freopen("speeding.in", "r", stdin);
|
|
freopen("speeding.out", "w", stdout);
|
|
|
|
int N, M;
|
|
cin >> N >> M;
|
|
|
|
vector<pair<int, int>> speedLimits(N);
|
|
for (int i = 0; i < N; i++) {
|
|
int len, speed;
|
|
cin >> len >> speed;
|
|
speedLimits[i] = pair<int, int>(len, speed);
|
|
}
|
|
|
|
vector<pair<int, int>> bessieSpeeds(M);
|
|
for (int i = 0; i < M; i++) {
|
|
int len, speed;
|
|
cin >> len >> speed;
|
|
bessieSpeeds[i] = pair<int, int>(len, speed);
|
|
}
|
|
|
|
int remainingRoad = speedLimits[0].first;
|
|
int remainingJourney = bessieSpeeds[0].first;
|
|
int res = 0, j = 0, i = 0;
|
|
|
|
while (i < N && j < M) {
|
|
res = max(res, bessieSpeeds[j].second - speedLimits[i].second);
|
|
|
|
int chunk = min(remainingRoad, remainingJourney);
|
|
remainingRoad -= chunk;
|
|
remainingJourney -= chunk;
|
|
|
|
if (remainingRoad == 0 && ++i < N) {
|
|
remainingRoad = speedLimits[i].first;
|
|
}
|
|
if (remainingJourney == 0 && ++j < M) {
|
|
remainingJourney = bessieSpeeds[j].first;
|
|
}
|
|
}
|
|
cout << res;
|
|
}
|