Codeforces 81 C. Average Score

本文介绍了一个算法,用于解决学生Polycarp如何在其两门课程中分配他的成绩,以实现平均分的最大化。通过将成绩分为Safety Studies和PE两门课程,算法确保了总平均分最高,同时满足每门课程的成绩数量限制。


排序...


C. Average Score
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.

Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:

  • there are exactly a Safety Studies marks,
  • there are exactly b PE marks,
  • the total average score in both subjects is maximum.

An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).

Input

The first line contains an integer n (2 ≤ n ≤ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 ≤ a, b ≤ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 5), they are Polycarp's marks.

Output

Print the sequence of integers f1, f2, ..., fn, where fi (1 ≤ fi ≤ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.

The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 ≤ j ≤ n) that pi = qi for all 1 ≤ i < j, аnd pj < qj.

Sample test(s)
input
5
3 2
4 4 5 4 4
output
1 1 2 1 2 
input
4
2 2
3 5 4 5
output
1 1 2 2 
input
6
1 5
4 4 4 5 4 4
output
2 2 2 1 2 2 
Note

In the first sample the average score in the first subject is equal to 4, and in the second one — to 4.5. The total average score is 8.5.



/**
 * Created by ckboss on 14-10-7.
 */
import java.util.*;

public class AverageScore {

    static final int maxn=100100;
    static int[] sorce = new int[maxn];
    static int[] fen = new int[10];
    static int[] fena=new int[10];
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int a=in.nextInt(),b=in.nextInt();
        for(int i=1;i<=n;i++)
        {
            sorce[i]=in.nextInt();
            fen[sorce[i]]++;
        }

        if(b-a<0){
            ///分给a的数要尽量小
            int ta=a;
            for(int i=1;i<=5&&ta>0;i++){
                if(fen[i]<=ta) {
                    fena[i]+=fen[i];
                    ta-=fen[i];
                }
                else{
                    fena[i]+=ta;
                    ta=0;
                }
            }
            for(int i=1;i<=n;i++){
                if(fena[sorce[i]]>0){
                    System.out.print(1+" ");
                    fena[sorce[i]]--;
                }
                else{
                    System.out.print(2+" ");
                }
            }
        }
        else if(b==a){
            for(int i=0;i<n;i++){
                int c;
                if(i+1<=a) c=1;
                else c=2;
                System.out.print(c+" ");
            }
        }
        else if(b-a>0){
            ///分给a的数要尽量大
            int ta=a;
            for(int i=5;i>=1&&ta>0;i--){
                if(fen[i]<=ta) {
                    fena[i]+=fen[i];
                    ta-=fen[i];
                }
                else{
                    fena[i]+=ta;
                    ta=0;
                }
            }
            for(int i=1;i<=n;i++){
                if(fena[sorce[i]]>0){
                    System.out.print(1+" ");
                    fena[sorce[i]]--;
                }
                else{
                    System.out.print(2+" ");
                }
            }
        }
        System.out.println("");
    }
}



转载于:https://www.cnblogs.com/ljbguanli/p/6970249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值