Xiao Ming and debts up! ! !

Xiao Ming bill! ! ! ! !

Hey, you say what a bad throw, partial lost that wallet. Even if you lose you can not lose wallet Ah! ! ! There wallet ID credit card Mobile phone car keys house keys, as well as Money! Money is important you know? It can be used to buy candy sugar triangle spicy Pioli to, or even wander the Earth assembling toys! ! !
You tell him! ! !

Send him a map!


It does not help the white does not help, with ZanDragon helpLiangshan heroes Road see injustice soon coax"run!"Properties, which help set the busy! ! !
Former military: the beginning of the victory of Ma generals look at the question, Ma C ++ code tiger generals view
the army: Ma generals victory Appreciation step generals part of the development of C ++ code Long Code
after the military: resorting to force teenager thumbs final victory seek
to develop people: Niubi who 107003CN171 APC
PS (Quantity: nickname real name)

Look at the title

Description [title]

Xiao Ming at a party, accidentally lost his wallet in the next day, Xiao Ming will face a series of procedures and piled up card bill ... in every possible way begged Xiao Ming, the boss finally agreed to delay the bill Payment time. The boss may also proposed, must choose the maximum and minimum of two denominations from all bills not yet paid in, and put them pay. You have not paid the bill will be retained until the next day. Ask you to help him calculate the payment order.

[Enter]

Line 1: a positive integer N (N≤15,000), represents Xiaoming go through the total number of days CUP card.

Line 2 to line N + 1: Each row describes billing day received. First, a non-negative integer M≤100, represents the number of the day of receipt of the bill, followed by M positive integers (less than 1,000,000,000), indicate the denomination of each bill.

Input data can ensure payment of two bills a day.

[Output]

Total N output lines, each line separated by a space two integers representing the minimum denomination of each day and the maximum payable checks denomination.

[Sample input]

4
3 3 6 5
2 8 2
3 7 1 7
0

[Sample Output]

3 6
2 8
1 7
5 7

【source】

No

view

Two heap! A large root a small root! ! ! Output count empty! ! ! ! !

Part Appreciation

noI will not tell you about it! - I'll tell you concerned about the content portion of Appreciation

Code

#include<bits/stdc++.h>
using namespace std;
int m,n,w,n1,n2;
struct data{
    int k,p;
}f1[1500005],f2[1500005],b;
bool r[1500005];
void d1() 
{
    while(r[f1[1].p]==1)
    {
     f1[1]=f1[n1];n1--;
     if(n1==0)break;
     int i=1,j=2;
     while(j<=n1)
      {
        if(j<n1&&(f1[j].k<f1[j+1].k||f1[j].k==f1[j+1].k&&f1[j].p<f1[j+1].p))j++;
        if(f1[i].k<f1[j].k||f1[i].k==f1[j].k&&f1[i].p<f1[j].p)
        {
            swap(f1[i],f1[j]);;
            i=j;j=i*2;
        }
        else break;
      } 
    }
}
void d2() 
{
    while(r[f2[1].p]==1)
    {
     f2[1]=f2[n2];n2--;
     if(n2==0)break;
     int i=1,j=2;
     while(j<=n2)
      {
        if(j<n2&&(f2[j].k>f2[j+1].k||f2[j].k==f2[j+1].k&&f2[j].p>f2[j+1].p))j++;
        if(f2[i].k>f2[j].k||f2[i].k==f2[j].k&&f2[i].p>f2[j].p)
        {
            swap(f2[i],f2[j]);;
            i=j;j=i*2;
        }
        else break;
      } 
    }
}
void u1() 
{
    f1[++n1]=b;
    int i=n1,j=n1/2;
    while(j>=1)
      {
        if(f1[i].k>f1[j].k||f1[i].k==f1[j].k&&f1[i].p>f1[j].p)
         {
            swap(f1[i],f1[j]);;
            i=j;j/=2;
         }
        else 
         break;
      }
}
void u2()
{
    f2[++n2]=b;
    int i=n2,j=n2/2;
    while(j>=1)
      {
        if(f2[i].k<f2[j].k||f2[i].k==f2[j].k&&f2[i].p<f2[j].p)
         {
            swap(f2[i],f2[j]);;
            i=j;j/=2;
         }
        else 
         break;
      }
}
int main()
{
 scanf("%d",&n);
 for(int i=1;i<=n;i++)
  {
    scanf("%d",&m);
    for(int j=1;j<=m;j++)
    {
        scanf("%d",&b.k);
        b.p=++w;
        u1();
        u2();
    }
    printf("%d %d\n",f2[1].k,f1[1].k);
    r[f1[1].p]=1;r[f2[1].p]=1;
    d1(),d2();
  }
  return 0;
}

Seeking thumbs up

Points by Zanga attention! ! !

Points by Zanga attention! ! !

Points by Zanga attention! ! !

Points by Zanga attention! ! !

Points by Zanga attention! ! !
Points by Zanga attention! ! !

Points by Zanga attention! ! !
Points by Zanga attention! ! !

Guess you like

Origin www.cnblogs.com/107003CN171yunbingche/p/12080937.html