[关闭]
@xunuo 2017-02-18T21:10:17.000000Z 字数 2315 阅读 1178

Codeforces 767 A--Snacktower


time limit per test 2 seconds memory limit per test 256 megabytes

暴力


Description

    According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.

    Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

图片

    However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

    Write a program that models the behavior of Ankh-Morpork residents.

Input

    The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

    The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Output

    Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

Examples

input

3
3 1 2

output

3

2 1

input

5
4 5 1 2 3

output

|
|5 4///这行前面还有一行
|
|
|3 2 1

Note

In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.

题意

其实这道题主要就是题意问题:有n天,每天都会掉一个零食下来,从小到大开始堆;
如第二组样例:n=5;说明接下来有1-5这5个数,输入的次序是4 5 1 2 3;
  第一天,输入的是4,但是最大的是5,所以第一天不放,第一行为空--"\n";
  第二天,输入的是5,是最大的数,所以第二天放5 4;
  第三天,输入的是1,但是最大的数应该是3,所以第三行为空行;
  第四天,输入的是2,但是最大的数应该是3,所以第四行为空行;
  第五天,输入的是3,则应该在第五行输出3 2 1;

完整代码

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<algorithm>
  5. using namespace std;
  6. int a[100010];
  7. int b[100010];
  8. int main()
  9. {
  10. int n;
  11. while(scanf("%d",&n)!=EOF)
  12. {
  13. for(int i=0;i<n;i++)
  14. scanf("%d",&a[i]);
  15. int k=n;
  16. memset(b,-1,sizeof(b));
  17. for(int i=0;i<n;i++)
  18. {
  19. if(a[i]!=k)
  20. {
  21. b[a[i]]=a[i];
  22. printf("\n");
  23. }
  24. else
  25. {
  26. k--;
  27. printf("%d",a[i]);
  28. if(i!=0)
  29. {
  30. for(int j=k;j>=n-i;j--)
  31. {
  32. if(b[j]==-1)
  33. break;
  34. else
  35. {
  36. k--;
  37. printf(" %d",b[j]);
  38. b[j]=-1;
  39. }
  40. }
  41. }
  42. printf("\n");
  43. }
  44. }
  45. }
  46. return 0;
  47. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注