C - Emergency Evacuation
https://vjudge.net/contest/394066#problem/C
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdlib> #include <ctime> #include <deque> #include <iomanip> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <iterator> #include <utility> #include <sstream> #include <limits> #include <numeric> #include <functional> using namespace std; #define gc getchar() #define mem(a) memset(a,0,sizeof(a)) #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef char ch; typedef double db; const double PI=acos(-1.0); const double eps=1e-6; const int inf=0x3f3f3f3f; const int maxn=1e5+10; const int maxm=100+10; const int N=1e6+10; const int mod=1e9+7; int I[500005] = {0}; int J[500005] = {0}; int t_cnt[1000000] = {0}; int main() { int r , s , p; cin >> r >> s >> p; int t = 0; int max_t = 0; int delay = 0; int ans = 0; for(int i = 0;i<p;i++) { cin >> I[i] >> J[i]; } for(int i = 0;i<p;i++) { if(J[i] <= s) { t = s-J[i]+1 + r-I[i]+1; } else { t = J[i]-s + r-I[i]+1; } //cout<<t <<endl; if(t > max_t) { max_t = t; } t_cnt[t] ++; } for(int i = 1;i <= max_t;i++) { if(t_cnt[i]) { delay += t_cnt[i]-1; } else { if(delay > 0) delay -= 1; } } //cout<<endl<<delay<<endl; ans = max_t + delay; /* for(int i = 1;i<=max_t;i++) { cout<<t_cnt[i]<<endl; } */ //cout << max_t <<" " <<delay<<endl; cout << ans; return 0; }