逆向思维,正着做有点难想,但反着做,让每个人回到自己位置,这就比较好做了。
贪心就行。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<bitset>
#include<list>
#include<set>
#include<utility>
#include<functional>
#include<iomanip>
#define IO ios::sync_with_stdio(false)
#define eps 1e-7
#define int long long
using namespace std;
struct node
{
int x,y;
}a[505*505*2];
bool cmp(node x,node y)
{
return x.x+x.y>y.x+y.y;
}
int r,s,p;
signed main()
{
cin>>r>>s>>p;
for(int i=1;i<=p;i++)
{
cin>>a[i].x>>a[i].y;
a[i].x=r-a[i].x;
if(a[i].y>s)
{
a[i].y-=s;
}
else
{
a[i].y=s-a[i].y+1;
}
}
sort(a+1,a+p+1,cmp);
int ans=-1;
for(int i=1;i<=p;i++)
{
ans=max(ans,i+(a[i].x+a[i].y));
}
cout<<ans;
}