Poj 2442 Sequence

Source: Internet
Author: User
Sequence
Time limit:6000 ms   Memory limit:65536 K
Total submissions:7019   Accepted:2266


N sequences are given. Each sequence has each element. One element is extracted from each sequence and the first n smallest and

Priority queue

#include<cstring>#include<cstdio>#include<cstring>#include<queue>#include<iostream>#include<algorithm>using namespace std;int main(){    int cas,n,m,i,j;    int a[2005],b[2005];    priority_queue<int,deque<int>,less<int> >big;    scanf("%d",&cas);    while(cas--)    {        scanf("%d%d",&m,&n);        for(i=0;i<n;i++)              scanf("%d",&a[i]);              sort(a,a+n);              for(i=1;i<m;i++)              {                  for(j=0;j<n;j++)                  {                      scanf("%d",&b[j]);                      big.push(a[0]+b[j]);                  }                  sort(b,b+n);                  for(int k=1;k<n;k++)                    for(int l=0;l<n;l++)                  {                      if(a[k]+b[l]>big.top())                        break;                      big.pop();                      big.push(a[k]+b[l]);                  }                  for(int k=0;k<n;k++)                  {                      a[n-k-1]=big.top();                      big.pop();                  }              }              printf("%d",a[0]);              for(i=1;i<n;i++)                printf(" %d",a[i]);              printf("\n");    }    return 0;}


Poj 2442 Sequence

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.