Codeforces Round #252 (Div. 2)

来源:互联网 发布:好用的化妆品 知乎 编辑:程序博客网 时间:2024/06/02 05:57
A. Valera and Antique Items
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera is a collector. Once he wanted to expand his collection with exactly one antique item.

Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller issij. Valera gets on well with each of the n sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.

Unfortunately, Valera has only v units of money. Help him to determine which of the n sellers he can make a deal with.

Input

The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has.

Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki (104 ≤ sij ≤ 106) — the current prices of the items of the i-th seller.

Output

In the first line, print integer p — the number of sellers with who Valera can make a deal.

In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.

Sample test(s)
input
3 500001 400002 20000 600003 10000 70000 190000
output
31 2 3
input
3 500001 500003 100000 120000 1100003 120000 110000 120000
output
0
Note

In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a20000 item from the second seller, and a 10000 item from the third seller.

In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.

//31 ms 0 KB#include<stdio.h>int s[1007];int main(){    int n,m;    while(scanf("%d%d",&n,&m)!=EOF)    {        int count=0;        int k=0;        for(int i=1;i<=n;i++)        {            int a,b,flag=1;            scanf("%d",&a);            for(int j=1;j<=a;j++)            {                scanf("%d",&b);                if(m>b&&flag){count++;flag=0;s[k++]=i;}            }        }        printf("%d\n",count);        if(count)        {            for(int i=0;i<k-1;i++)            printf("%d ",s[i]);        printf("%d\n",s[k-1]);        }    }}

B. Valera and Fruits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera loves his garden, where n fruit trees grow.

This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).

Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more thanv fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?

Input

The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.

Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.

Output

Print a single integer — the maximum number of fruit that Valera can collect.

Sample test(s)
input
2 31 52 3
output
8
input
5 103 202 201 204 205 20
output
60
Note

In the first sample, in order to obtain the optimal answer, you should act as follows.

  • On the first day collect 3 fruits from the 1-st tree.
  • On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
  • On the third day collect the remaining fruits from the 2-nd tree.

In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.

//31 ms 0 KB#include<stdio.h>#include<algorithm>using namespace std;struct node{    int a,b;} s[3004];bool cmp(node x,node y){    return x.a<y.a;}int main(){    int n,v,i,j,ans;    while(scanf("%d%d",&n,&v)!=EOF)    {        int maxn=0;        for(i=0; i<n; i++)        {            scanf("%d%d",&s[i].a,&s[i].b);            if(s[i].a>maxn) maxn=s[i].a;        }        sort(s,s+n,cmp);        ans=0;        for(i=1; i<=maxn+1; i++)        {            int r=v;            for(int j=0;j<n;j++)            {                if(i!=s[j].a&&i!=s[j].a+1) continue;                if(s[j].b>=r)                {                    s[j].b-=r;                    ans+=r;                    r=0;                    break;                }                else if(s[j].b)                {                    r-=s[j].b;                    ans+=s[j].b;                    s[j].b=0;                }                if(!r)break;            }        }        printf("%d\n",ans);    }    return 0;}

C. Valera and Tubes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).

Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1)(x2, y2)...(xr, yr), that:

  • r ≥ 2;
  • for any integer i (1 ≤ i ≤ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
  • each table cell, which belongs to the tube, must occur exactly once in the sequence.

Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:

  • no pair of tubes has common cells;
  • each cell of the table belongs to some tube.

Help Valera to arrange k tubes on his rectangle table in a fancy manner.

Input

The first line contains three space-separated integers n, m, k (2 ≤ n, m ≤ 3002 ≤ 2k ≤ n·m) — the number of rows, the number of columns and the number of tubes, correspondingly.

Output

Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integersxi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).

If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.

Sample test(s)
input
3 3 3
output
3 1 1 1 2 1 33 2 1 2 2 2 33 3 1 3 2 3 3
input
2 3 1
output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note

Picture for the first sample:

Picture for the second sample:


模拟从第一个开始,蛇形输出,前k-1个输出两个格,最后一个将剩余的都输出。

//46 ms 0 KB#include<stdio.h>int x[307],y[307];int main(){    int n,m,k;    while(scanf("%d%d%d",&n,&m,&k)!=EOF)    {        if(k>1)        {            int count=0,x,y,flag=0;            for(int i=1; i<=n; i++)            {                for(int j=1; j<=m; j++)                {                    if(count%2==0)printf("2");                    count++;                    if(i&1)printf(" %d %d",i,j);                    else printf(" %d %d",i,m-j+1);                    if(count%2==0)                    {                        printf("\n");                    }                    if(count==(k-1)*2)                    {                        x=i;                        y=j;                        flag=1;                        break;                    }                }                if(flag)break;            }            int a=m*n-count;            printf("%d",a);            for(int i=x; i<=n; i++)            {                 for(int j=y+1; j<=m; j++)                {                    if(i&1)printf(" %d %d",i,j);                    else printf(" %d %d",i,m-j+1);                    y=0;                }                y=0;            }            printf("\n");        }        else        {            printf("%d",n*m);            for(int i=1;i<=n;i++)                for(int j=1;j<=m;j++)                    if(i&1)printf(" %d %d",i,j);                    else printf(" %d %d",i,m-j+1);            printf("\n");        }    }    return 0;}


0 0