Codeforces Round #311 (Div. 2) A. Ilya and Diplomas
原题:http://codeforces.com/contest/557/problem/A
题目大意:给三个[min,max]格式的区间,A,B,C,分配n个东西, 问怎么分配在满足min的前提先, 按照满足A,B,C的先后顺序,最大分配.
分析:n个东西, 因为要满足B,C的min, 所以先拿出B的min和C的min, 剩下的就是n – min_B – min_C, 然后取min(max_A, n – min_B – min_C) 就是A的数量, 同理类推做B. 很水的题.
public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); int min_1 = in.readInt(); int max_1 = in.readInt(); int min_2 = in.readInt(); int max_2 = in.readInt(); int min_3 = in.readInt(); int max_3 = in.readInt(); int one = Math.min(max_1, n - min_2 - min_3); int rest_one = n - one; int two = Math.min(max_2, rest_one - min_3); int rest_two = rest_one - two; out.print(one +" " + two + " " + rest_two); }
Leave A Comment