Gym 100703I --- Endeavor for perfection (ruler), unlimited challenge 100703

Source: Internet
Author: User

Gym 100703I --- Endeavor for perfection (ruler), unlimited challenge 100703

Question Link

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 shoshould tell Princess about it.

Prince decided that he needs some extra knowledge and skills. He choseNFields in which he wanted to gain knowledge and skills most of all. After this, he learned thatM1, bytes,M2, middle..., middle ,...,MNCourses and trainings of each of fields exist.

Prince took a close look at descriptions of courses and trainings and drew a table, in whichSIjIs a value by whichITh skill is increased after studyingJTh course (JPriority = Priority 1, priority 2, priority..., priority ,...,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 wocould be as minimum as possible.

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

Input

The first line contains integerN(1 digit ≤ DigitNLimit ≤ limit 200)-the number of fields which Prince is interested in.

The second line containsNIntegersM1, bytes,M2, middle..., middle ,...,MN(1 digit ≤ DigitMJMinimum ≤ maximum 1000, minimum,JPriority = Priority 1, priority 2, priority..., priority ,...,N)-The number of courses for each of fields.

The nextNLines contain valuesSIj(1 digit ≤ DigitSIjLimit ≤ limit 109)-knowledges and skills, which Prince wocould gain at the courses. The first of theseNLines contains valuesS11, middle,S12, middle..., middle ,...,S1M1, the second-valuesS21, middle,S22, middle..., middle ,...,S2M2, etc.

The valuesSIjAre 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 printNIntegers-numbers of courses which Prince shocould 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


Enter n, and then enter n number, which indicates the number of each row in the next n rows, select a number in each row to minimize the difference between the maximum and minimum values of n, and output the smallest difference and the column number of The number selected in each row;

Train of Thought: Take the ruler, put the number of n rows together in ascending order, define s = 0 and e = 0, meaning s ~ In a section of e, e moves to the right until the range contains the number of n rows, then node [e]. x-node [s]. x is the minimum difference between the n rows selected from this range, and then s ++, and then let e shift right to calculate the minimum difference between the n rows ......

The Code is as follows:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>#include <bitset>using namespace std;const int M=1e9+5;const int maxn=2e5+5;int A[205],cnt[205],vis[205];struct Node{    int x,h,l;}node[maxn],ans[205];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,0,sizeof(cnt));       memset(vis,0,sizeof(vis));       for(int i=0;i<n;i++)           scanf("%d",&A[i]);       int tot=0;       for(int i=0;i<n;i++)       for(int j=1;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=0,e=0,sum=0;       int pos1,pos2;       while(1)       {           while(e<tot&&sum<n){               cnt[node[e].h]++;               if(cnt[node[e].h]==1) sum++;               e++;           }           if(sum<n) break;           if(node[e-1].x-node[s].x<tmp){               tmp=node[e-1].x-node[s].x;               pos1=s;               pos2=e-1;           }           if(tmp==0) break;           if(cnt[node[s].h]==1) sum--;           cnt[node[s].h]--;           s++;       }       int p=0;       for(int i=pos1;i<=pos2;i++)       {           if(vis[node[i].h]==0)           {              vis[node[i].h]=1;              ans[p].h=node[i].h;              ans[p++].l=node[i].l;           }       }       sort(ans,ans+n,cmp2);       printf("%d\n",tmp);       for(int i=0;i<n;i++)        printf("%d%c",ans[i].l,(i+1==n)?'\n':' ');    }    return 0;}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.