Created
December 12, 2018 12:22
-
-
Save eiichiroi/523fc734f5030fa81ff342b56e5d5c81 to your computer and use it in GitHub Desktop.
ICPC 2018 Yokohama Regional Problem C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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