알고리즘/softeer
Softeer - GBC
유이얼
2021. 8. 20. 01:26
https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=584&sw_prbl_sbms_sn=14465
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <string>
using namespace std;
int max(int a, int b) {
return a > b ? a : b;
}
int main() {
int N, M;
cin >> N >> M;
// length & speed
vector<pair<int, int>> speed(N);
vector<pair<int, int>> test(M);
for (int i = 0; i < N; ++i) {
cin >> speed[i].first >> speed[i].second;
if (i)
speed[i].first += speed[i - 1].first;
}
for (int i = 0; i < M; ++i) {
cin >> test[i].first >> test[i].second;
if (i)
test[i].first += test[i - 1].first;
}
vector<pair<int, int>> uni;
int si = 0;
int ti = 0;
int ans = 0;
while (si < N || ti < M) {
ans = max(ans, test[ti].second - speed[si].second);
if (speed[si].first < test[ti].first) {
//uni.push_back({ speed[si].first, test[ti].second - speed[si].second });
++si;
}
else if (speed[si].first > test[ti].first) {
//uni.push_back({ test[ti].first, test[ti].second - speed[si].second });
++ti;
}
else {
//uni.push_back({ speed[si].first, test[ti].second - speed[si].second });
++si, ++ti;
}
}
cout << ans << "\n";
return 0;
}