排序...
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).
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.
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.
5 3 2 4 4 5 4 4
1 1 2 1 2
4 2 2 3 5 4 5
1 1 2 2
6 1 5 4 4 4 5 4 4
2 2 2 1 2 2
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("");
    }
}
 
                   
                   
                   
                   本文介绍了一个算法,用于解决学生Polycarp如何在其两门课程中分配他的成绩,以实现平均分的最大化。通过将成绩分为Safety Studies和PE两门课程,算法确保了总平均分最高,同时满足每门课程的成绩数量限制。
本文介绍了一个算法,用于解决学生Polycarp如何在其两门课程中分配他的成绩,以实现平均分的最大化。通过将成绩分为Safety Studies和PE两门课程,算法确保了总平均分最高,同时满足每门课程的成绩数量限制。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                  
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            