题目链接

http://codeforces.com/problemset/gymProblem/100703/I

Description

standard input/output
Statements

As a matter of fact, Dragon knows what Prince is interested in now. Prince uses to spend his rare off days learning different courses and trainings. But Dragon doubts whether he should tell Princess about it.

Prince decided that he needs some extra knowledge and skills. He chose n fields in which he wanted to gain knowledge and skills most of all. After this, he learned that m1, m2, ..., mn courses and trainings of each of fields exist.

Prince took a close look at descriptions of courses and trainings and drew a table, in which sij is a value by which ith skill is increased after studying jth course (j = 1, 2, ..., mi).

Prince believes that his basic knowledge and skills in all these fields are negligible, so they can be considered zero. He wants to evolve his knowledge and skills harmonically. In his opinion, he will reach the greatest harmony if he chooses one course for each field in such a way that difference between the highest and the lowest their increases would be as minimum as possible.

Your task is to find the courses which Prince should choose.

Input

The first line contains integer n (1 ≤ n ≤ 200) — the number of fields which Prince is interested in.

The second line contains n integers m1, m2, ..., mn (1 ≤ mj ≤ 1000,  j = 1, 2, ..., n) — the number of courses for each of fields.

The next n lines contain values sij (1 ≤ sij ≤ 109) — knowledges and skills, which Prince would gain at the courses. The first of thesen lines contains values s11, s12, ..., s1m1, the second — values s21, s22, ..., s2m2, etc.

The values sij are listed in the numerical order of courses for each of the fields.

Output

In the first line print one integer — minimum difference between the highest and the lowest numbers of increase.

In the second line print n integers — numbers of courses which Prince should choose. List the numbers in the same order in which the fields are listed.

If there is more than one answer — choose any of them.

Sample Input

Input
2
2 3
4 3
3 1 2
Output
0
2 1
Input
4
3 5 4 5
8 7 15
3 10 4 8 5
4 4 4 5
1 2 12 8 9
Output
3
2 5 4 4 题意:输入一个n,然后输入n个数,表示接下来输入的n行每行的数的个数,求在每行中选择一个数使得这n个数的最大值与最小值的差最小,输出最小的差值和每行选择的数的列号; 思路:尺取,将n行的数放在一起从小到大排序,定义s=0和e=0,表示s~e的一段区间,e向右移动,直到这个区间包含n行的数,那么node[e].x-node[s].x便是从这个区间选择的n行数的最小差值,然后s++,再让e右移,计算区间n行数最小差值...... 代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
using namespace std;
const int M=1e9+;
const int maxn=2e5+;
int A[],cnt[],vis[];
struct Node
{
int x,h,l;
}node[maxn],ans[];
bool cmp1(const Node s1,const Node s2)
{
return s1.x<s2.x;
}
bool cmp2(const Node s1,const Node s2)
{
return s1.h<s2.h;
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(cnt,,sizeof(cnt));
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
scanf("%d",&A[i]);
int tot=;
for(int i=;i<n;i++)
for(int j=;j<=A[i];j++)
{
scanf("%d",&node[tot].x);
node[tot].h=i;
node[tot++].l=j;
}
sort(node,node+tot,cmp1);
int tmp=M,s=,e=,sum=;
int pos1,pos2;
while()
{
while(e<tot&&sum<n){
cnt[node[e].h]++;
if(cnt[node[e].h]==) sum++;
e++;
}
if(sum<n) break;
if(node[e-].x-node[s].x<tmp){
tmp=node[e-].x-node[s].x;
pos1=s;
pos2=e-;
}
if(tmp==) break;
if(cnt[node[s].h]==) sum--;
cnt[node[s].h]--;
s++;
}
int p=;
for(int i=pos1;i<=pos2;i++)
{
if(vis[node[i].h]==)
{
vis[node[i].h]=;
ans[p].h=node[i].h;
ans[p++].l=node[i].l;
}
}
sort(ans,ans+n,cmp2);
printf("%d\n",tmp);
for(int i=;i<n;i++)
printf("%d%c",ans[i].l,(i+==n)?'\n':' ');
}
return ;
}
 

Gym 100703I---Endeavor for perfection(尺取)的更多相关文章

  1. CF GYM 100703I Endeavor for perfection

    题意:有n个学习领域,每个领域有m个课程,学习第i个领域的第j个课程可以获得sij个技能点,在每个领域中选择一个课程,要求获得的n个技能点的最大值减最小值最小,输出符合要求的策略. 解法:尺取法.将课 ...

  2. Gym 101257G:24(尺取)

    http://codeforces.com/gym/101257/problem/GGym 101257G 题意:给出n个人,和一个数s,接下来给出每个人当前的分数和输掉的概率.当一个人输了之后就会掉 ...

  3. NOJ 1072 The longest same color grid(尺取)

    Problem 1072: The longest same color grid Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit in ...

  4. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  5. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  6. poj2566尺取变形

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  7. poj2100还是尺取

    King George has recently decided that he would like to have a new design for the royal graveyard. Th ...

  8. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

  9. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

随机推荐

  1. 利用Hexo搭建个人博客-博客初始化篇

    上一篇博文 <利用Hexo搭建个人博客-环境搭建篇> 中,我们讲解了利用Hexo搭建个人博客应该要配置哪些环境.相信大家已经迫不及待的想要知道接下来应该要怎么把自己的博客搭起来了,下面,让 ...

  2. C# 用原生JS进行文件的上传

    1.此文章是用原生JS来进行文件的上传,有两个版本,一个不用ajax,一个用ajax. 1)非AJAX <!DOCTYPE html> <html> <head> ...

  3. Android Drawable 那些不为人知的高效用法

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/43752383,本文出自:[张鸿洋的博客] 1.概述 Drawable在我们平时的 ...

  4. 《Qt Quick 4小时入门》学习笔记4

    http://edu.csdn.net/course/detail/1042/14806?auto_start=1 Qt Quick 4小时入门 第七章:处理鼠标与键盘事件 1.处理鼠标事件 鼠标信号 ...

  5. Powershell 切换IE代理

    买了一个穿越防火墙的代理,在 Windows 下每次手动设置代理都好麻烦,最后不断尝试 Powershell 来设置,最后也终于成功了.   其实利用 Powershell 来设置 IE 的代理,就是 ...

  6. 【WP开发】记录屏幕操作

    在某些应用中,比如游戏,有时候需要将用户的操作记录下来.ScreenCapture类提供了这个功能.但必须注意的是:此屏幕记录功能只对当前应用程序的屏幕有效,即只有当前应用程序在前台运行时才有效. 与 ...

  7. hdu4831 Scenic Popularity(线段树)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4831 题目大概意思就是有多个风景区和休息区,每个风景区有热度,休息区的热度与最接近的分景区的热度相同, ...

  8. preg_match的isU代表什么意义

    正则后面的/(.*)/isU  ,“isU”参数代表什么意思?这是正则中的修正符.i是同时查找大小写字母,s是圆点(.)匹配所有字符,包括换行符.如果没有设定s,则不包括换行符.U是反转了匹配数量的值 ...

  9. android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画

    ViewAnimationUtils.createCircularReveal()的简介: ViewAnimationUtils.createCircularReveal()是安卓5.0才引入的,快速 ...

  10. 实验记录:Oracle redo logfile的resize过程

    实验记录:Oracle redo logfile的resize过程. 实验环境:RHEL 6.4 + Oracle 11.2.0.3 单实例 文件系统 实验目的:本实验是修改redo logfile的 ...