• B. Valera and Contest


    B. Valera and Contest
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.

    After the contest was over, Valera was interested in results. He found out that:

    • each student in the team scored at least l points and at most r points;
    • in total, all members of the team scored exactly sall points;
    • the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 ≥ a2 ≥ ... ≥ an), then sk = a1 + a2 + ... + ak.

    However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.

    Input

    The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 ≤ n, k, l, r ≤ 1000; l ≤ r; k ≤ n; 1 ≤ sk ≤ sall ≤ 106).

    It's guaranteed that the input is such that the answer exists.

    Output

    Print exactly n integers a1, a2, ..., an — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.

    Sample test(s)
    Input
    5 3 1 3 13 9
    Output
    2 3 2 3 3 
    Input
    5 3 1 3 15 9
    Output
    3 3 3 3 3 
    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define maxn 1010
    #define LL long long
    #define mod 1000000007
    using namespace std ;
    
    int ans[maxn] , tt , mm , sk , ll ;
    bool getans( int u , int L , int R )
    {
        if( mm == sk ) return true ;
    
            ans[u]++ ;
            mm++ ;
            if(tt)tt-- ;
            else
            {
                ans[ll]-- ;
                if(ans[ll] <= L) ll-- ;
            }
            if(mm == sk ) return true ;
            return false ;
    }
    int main()
    {
       int i , n ,m , j , k;
       int L , R , sum ;
      // freopen("in.txt","r",stdin) ;
       while( scanf("%d%d%d%d%d%d" , &n,&k,&L,&R,&sum,&sk ) != EOF )//n, k, l, r, sall, sk
       {
            j = sum/n ;
            tt = sum%n ;
            mm = 0 ;
            ll = n ;
            for( i = 1 ; i <= n ;i++ ){
                ans[i] = j ;
                if(i <= k) mm += j ;
            }
            i = 1 ;
              while(1){
                if(getans(i,L,R))break ;  // 每次都给一个增加1 
                  i++ ;
                if( i > k ) i = 1 ;
              }
            
           if(tt)
            {
                for( i = k+1 ; i <= n ;i++ )
                {
                    while( ans[i] < ans[k])
                    {
                        ans[i]++ ;
                        tt-- ;
                        if(tt==0) break ;
                    }
                    if(tt==0)break ;
                }
            }
            
         for( i = 1 ; i < n ;i++ ){
              printf("%d " ,ans[i]) ;
            }
            cout << ans[i] << endl ;
       }
       return 0 ;
    }
    
  • 相关阅读:
    二、跳转指定页面的JS代码
    一、常规的JS页面跳转代码
    您在前一家公司的离职原因是什么?
    如果你在这次面试中没有被录用,你怎么打算?
    如果你在这次面试中没有被录用,你怎么打算?
    针对你们单位业务工作中出现的问题,你提出了一些很好的建议,得到了同事们的赞同,但你的领导并不满意。在这种情况下,你怎么办?
    进程与线程的区别
    work13
    work12
    day09
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3450715.html
Copyright © 2020-2023  润新知