Codeforces 398 A. Cards


枚举a分成多少段,让a的部分尽量大,b的部分尽量小

A. Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below.

  1. At first, the score is 0.
  2. For each block of contiguous "o"s with length x the score increases by x2.
  3. For each block of contiguous "x"s with length y the score decreases by y2.
 

For example, if a = 6, b = 3 and ainta have arranged the cards in the order, that is described by string "ooxoooxxo", the score of the deck equals 22 - 12 + 32 - 22 + 12 = 9. That is because the deck has 5 blocks in total: "oo", "x", "ooo", "xx", "o".

User ainta likes big numbers, so he wants to maximize the score with the given cards. Help ainta make the score as big as possible. Note, that he has to arrange all his cards.

Input

The first line contains two space-separated integers a and b (0 ≤ a, b ≤ 105a + b ≥ 1) — the number of "o" cards and the number of "x" cards.

Output

In the first line print a single integer v — the maximum score that ainta can obtain.

In the second line print a + b characters describing the deck. If the k-th card of the deck contains "o", the k-th character must be "o". If the k-th card of the deck contains "x", the k-th character must be "x". The number of "o" characters must be equal to a, and the number of "x " characters must be equal to b. If there are many ways to maximize v, print any.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the%I64d specifier.

Sample test(s)
input
2 3
output
-1
xoxox
input
4 0
output
16
oooo
input
0 4
output
-16
xxxx


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const long long int INF=~0U>>1;

int main()
{
    long long int a,b;
    scanf("%I64d%I64d",&a,&b);
    if(a==0&&b!=0)
    {
        printf("%I64d\n",-b*b);
        while(b--) putchar('x'); return 0;
    }
    if(b==0&&a!=0)
    {
        printf("%I64d\n",a*a);
        while(a--) putchar('o'); return 0;
    }
    long long int mark=-1;
    long long int mmx=-INF;
    for(long long int i=1;i<=a;i++)
    {
        long long int part1=(long long int)(a-i+1)*(a-i+1)+(i-1);
        long long int part2=(long long int )(b/(i+1)+1)*(b/(i+1)+1)*(b%(i+1))+(long long int)(b/(i+1))*(b/(i+1))*(i+1-b%(i+1));
        if(part1-part2>mmx)
        {
            mmx=part1-part2;
            mark=i;
        }
    }

    printf("%I64d\n",mmx);
    for(int i=1;i<=mark+1;i++)
    {
        int t=b/(mark+1);
        while(t--) putchar('x');
        if(i<=b%(mark+1)) putchar('x');
        if(i==1)
        {
            t=a-mark+1;
            while(t--) putchar('o');
        }
        else if(i!=mark+1) putchar('o');
    }
    return 0;
}




你可能感兴趣的:(Codeforces 398 A. Cards)