\ (The core idea is to divide the discussion \)
The analysis of the topic as a whole, this question there are three cases:
(1)0
There is one of 0, the result is the other max;
Both are 0, the result is 0;
(2) a multi-party, the other is not enough to meet the \ ((contx + 1) * maxo <= counto \)
Or the \ ((conto + 1) * maxx <= countx \)
The result is: \ ((contx + 1) * Maxo + counto \) (the X-enough)
or
\ ((Cont0 + 1) * maxx + counto \) (O is not enough)
That is, even if one is not enough to take a time as a separator is not sufficient.
For example, 20522
The longest string of super beautiful invincible as: OOXOOXOOXOOXOOXOO
(3) otherwise, the result is maxn + maxm
Removal (1) (2) two special cases, the other cases can be used for all of the letters.
For example 8632
The longest string of super beautiful invincible as: OOOXXOOOXXOOXX
\ (My understanding is that \)
\ (First of all be clear, the longest string length maxx + maxo \)
\ (And this is a case of two kinds of letters just run out \)
\ (That we first consider the case of a party not enough, that is, the less each time that letter only as a delimiter still not enough \)
\ (This time less run out of letters, and more letters is the maximum number of divisions, certainly the best \)
\ (Special, there may be a party to zero, the special sentence \)
\ (The remaining cases can be fully utilized for maxx + maxo \)
#include <iostream>
using namespace std;
int main()
{
long long o,x,maxx,maxo;
while(cin>>maxo>>maxx>>o>>x)
{
if(o==0||maxo==0) cout<<min(maxx,x);
else if(x==0||maxx==0) cout<<min(maxo,o);
else if((maxx+1)*o<maxo) cout<<(maxx+1)*o+maxx;
else if((maxo+1)*x<maxx) cout<<(maxo+1)*x+maxo;
else cout<<maxx+maxo;//全部用完
cout<<endl;
}
return 0;
}