Skip to content

Instantly share code, notes, and snippets.

@eiichiroi
Created December 12, 2018 12:22
Show Gist options
  • Save eiichiroi/523fc734f5030fa81ff342b56e5d5c81 to your computer and use it in GitHub Desktop.
Save eiichiroi/523fc734f5030fa81ff342b56e5d5c81 to your computer and use it in GitHub Desktop.
ICPC 2018 Yokohama Regional Problem C
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Seat {
int x;
int y;
};
int distance(int r, int s, const Seat& seat) {
const int dx = (seat.x <= s) ? (s - seat.x + 1) : (seat.x - s);
const int dy = r - seat.y;
return dx + dy;
}
int solve(int r, int s, int p, const vector<Seat>& seats) {
vector<int> dist(p);
for (int i = 0; i < p; ++i) {
dist[i] = distance(r, s, seats[i]);
}
sort(dist.begin(), dist.end(), greater<int>());
int max_time = 0;
for (int i = 0; i < p; ++i) {
max_time = max(max_time, dist[i] + (i + 1));
}
return max_time;
}
int main() {
int r, s, p;
cin >> r >> s >> p;
vector<Seat> seats(p);
for (int i = 0; i < p; ++i) {
cin >> seats[i].y >> seats[i].x;
}
std::cout << solve(r, s, p, seats) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment