<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #598 (Div. 3) E. Yet Another Division Into Teams dp

      E. Yet Another Division Into Teams

      There are n students at your university. The programming skill of the i-th student is ai. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has 2?105 students ready for the finals!

      Each team should consist of at least three students. Each student should belong to exactly one team. The diversity of a team is the difference between the maximum programming skill of some student that belongs to this team and the minimum programming skill of some student that belongs to this team (in other words, if the team consists of k students with programming skills a[i1],a[i2],…,a[ik], then the diversity of this team is maxj=1ka[ij]?minj=1ka[ij]).

      The total diversity is the sum of diversities of all teams formed.

      Your task is to minimize the total diversity of the division of students and find the optimal way to divide the students.

      Input

      The first line of the input contains one integer n (3≤n≤2?105) — the number of students.

      The second line of the input contains n integers a1,a2,…,an (1≤ai≤109), where ai is the programming skill of the i-th student.

      Output

      In the first line print two integers res and k — the minimum total diversity of the division of students and the number of teams in your division, correspondingly.

      In the second line print n integers t1,t2,…,tn (1≤ti≤k), where ti is the number of team to which the i-th student belong.

      If there are multiple answers, you can print any. Note that you don't need to minimize the number of teams. Each team should consist of at least three students.

      Examples

      input
      5
      1 1 3 4 2
      output
      3 1
      1 1 1 1 1
      input
      6
      1 5 12 13 2 15
      output
      7 2
      2 2 1 1 2 1
      input
      10
      1 2 5 129 185 581 1041 1909 1580 8150
      output
      7486 3
      3 3 3 2 2 2 2 1 1 1

      Note

      In the first example, there is only one team with skills [1,1,2,3,4] so the answer is 3. It can be shown that you cannot achieve a better answer.

      In the second example, there are two teams with skills [1,2,5] and [12,13,15] so the answer is 4+3=7.

      In the third example, there are three teams with skills [1,2,5], [129,185,581,1041] and [1580,1909,8150] so the answer is 4+912+6570=7486.

      題意

      這個學校里面有n個學生,你需要給他們分成若干的隊伍,每個隊伍最少3個人。

      每個隊伍定義差異值是這個隊伍最強的人和最弱的人的能力值差。

      現在你需要構建若干個隊伍,使得差異值的總和最小。

      題解

      我們先排序,那么分隊伍一定是選擇排序后的連續幾個人組成一隊。

      然后每個隊伍一定人數最多為5個人,因為6個人就可以拆成兩隊,然后兩隊的代價一定是比一個隊伍的代價小。

      然后就是個簡單的dp了。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      const int maxn = 200005;
      int n;
      pair<int,int> k[maxn];
      int dp[maxn];
      int p[maxn];
      int fr[maxn];
      int ans_pos[maxn];
      int tot=0;
      void dfs(int x){
      	if(x==0)return;
      	tot++;
      	p[x]=1;
      	dfs(fr[x]);
      }
      int main(){
      	scanf("%d",&n);
      	for(int i=1;i<=n;i++){
      		scanf("%d",&k[i].first);
      		k[i].second=i;
      	}
      	sort(k+1,k+1+n);
      	memset(dp,-1,sizeof(dp));
      	dp[0]=0;
      	dp[3]=k[3].first-k[1].first;
      	for(int i=4;i<=n;i++){
      		for(int j=3;j<=6;j++){
      			if(dp[i-j]!=-1){
      				if(dp[i]==-1){
      					dp[i]=dp[i-j]+k[i].first-k[i-j+1].first;
      					fr[i]=i-j;
      				}
      				else{
      					if(dp[i-j]+(k[i].first-k[i-j+1].first)<dp[i]){
      						fr[i]=i-j;
      						dp[i]=dp[i-j]+k[i].first-k[i-j+1].first;
      					}
      				}
      			}
      		}
      	}
      
      	dfs(n);
      	cout<<dp[n]<<" "<<tot<<endl;
      	int tot2=1;
      	for(int i=1;i<=n;i++){
      		if(p[i]==0){
      			p[i]=tot2;
      		}else if(p[i]==1){
      			p[i]=tot2;
      			tot2++;
      		}
      	}
      	for(int i=1;i<=n;i++){
      		ans_pos[k[i].second]=p[i];
      	}
      	for(int i=1;i<=n;i++){
      		cout<<ans_pos[i]<<" ";
      	}
      	cout<<endl;
      }
      
      posted @ 2019-11-05 15:52  qscqesze  閱讀(620)  評論(1)    收藏  舉報
      主站蜘蛛池模板: 2019亚洲午夜无码天堂| 亚洲欧美高清在线精品一区二区 | 波多野结衣一区二区三区高清| 亚洲人成电影在线天堂色| 日韩乱码视频一区二区三区| 国产午夜精品福利视频| 国产男女猛烈无遮挡免费视频网站 | 人妻有码av中文字幕久久琪| 亚洲成人av在线资源| 中文毛片无遮挡高潮免费| 久久国产乱子精品免费女| 日韩精品人妻中文字幕| 国产成a人亚洲精v品无码性色| 国产精品 无码专区| 久久亚洲av成人一二三区| 中文字幕精品人妻av在线| 福利一区二区1000| 中文字幕av无码一区二区蜜芽三区| 老司机午夜精品视频资源| 长阳| 日韩丝袜欧美人妻制服| 狂躁女人双腿流白色液体| 亚洲国产美女精品久久久| 99久久亚洲综合精品成人网| 在线免费成人亚洲av| 国产精品久久精品国产| 国产精品美腿一区在线看| 国产午夜精品福利视频| 英吉沙县| 亚洲免费视频一区二区三区| FC2免费人成在线视频| 平湖市| 国内精品久久久久影视| 又粗又紧又湿又爽的视频| 草草浮力地址线路①屁屁影院| 国产熟女精品一区二区三区| 国产伦码精品一区二区| 奇米影视7777狠狠狠狠色| 摸丰满大乳奶水www免费| 亚洲综合无码明星蕉在线视频| 国产精品中文字幕av|