Codeforces Round # 585 (Div. 2) [Replenishment]

Foreword

Yesterday afternoon I looked D title, did not write right, because to fill the job, the plane quickly, and fight for the title this week finished up.

A Yellow Cards

Luo Gu CF1215A

At first I thought no good way, too embarrassed.

Sooke gives a big brother such method:

  • For \ (Min \) , we assume that each person give hair \ ((k-1) \ ) cards, \ (A_1 \) is \ ((k_1-1) \) , \ (A_2 \) is \ ( (k_2-1) \) , so that each person achieve a "saturation", and the rest will make each one a yellow card fate.

  • For \ (Max \) , we use violence to enumerate \ (i \) , in \ (a_1 \) put \ (i \) Zhang, in \ (a_2 \) put \ ((ni) \) Zhang, looking for maximum values like

Code

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
int n,a1,a2,k1,k2,Max,Min;
int main()
{
    a1 = read(), a2 = read(), k1 = read(), k2 = read(), n = read();
    Min = max(0, n-((k1-1)*a1+(k2-1)*a2));
    for(int i=0;i<=n;++i) {
        Max = max(Max, min(a1 ,i/k1)+min(a2, (n-i)/k2));
    }
    printf("%d %d\n",Min,Max);
    return 0;
}

Guess you like

Origin www.cnblogs.com/BaseAI/p/11529924.html