codechef The Army

Problem Description

N Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right.
In the test, there are M rounds. In each round, Captain selects one position. Soldier at that position will be numbered 0. All the soldiers to the right of selected position will be numbered one greater than the soldier to his left. All the soldiers to the left of selected position will be numbered one greater than the soldier to his right.
eg. if N = 6 and selected position is 3, then the numbering will be [3, 2, 1, 0, 1, 2].
After M rounds, Captain asked each soldier to shout out the greatest number he was assigned during the M rounds. In order to check the correctness, Captain asked you to produce the correct values for each soldier (That is the correct value each soldier should shout out).

Input

The first line of the input contains an integer T denoting the number of test cases.
First line of each test case contains two integers, N and M.
Second line of each test case contains M integers, the positions selected by Captain, in that order.

Output

For each test case, output one line with N space separated integers.

Constraints

1 ≤ T ≤ 10^4
1 ≤ N ≤ 10^5
1 ≤ M ≤ 10^5
1 ≤ Sum of N over all testcases ≤ 10^5
1 ≤ Sum of M over all testcases ≤ 10^5
0 ≤ Positions selected by captain ≤ N-1

Example

Input

2
4 1
1
6 2
2 3

Output

1 0 1 2
3 2 1 1 2 3

题解

模拟即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
#define inf 1<<30
#define eps -1
using namespace std;
int T,n,m,minw,maxw;
void init()
{
	scanf("%d%d",&n,&m);
	maxw=eps; minw=inf;
	int i,x;
	for(i=1;i<=m;i++)
	   {scanf("%d",&x);
	    maxw=max(maxw,x);
	    minw=min(minw,x);
	   }
}
void find()
{
	int i;
	for(i=0;i<n;i++)
	   {if(i<minw) printf("%d",maxw-i);
	    else if(i>maxw) printf("%d",i-minw);
	    else printf("%d",max(abs(maxw-i),abs(minw-i)));
	    if(i<n-1) printf(" ");
	    else printf("\n");
	   }
}
int main()
{
	scanf("%d",&T);
	while(T--)
	   {init(); find();}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C1. Powering the Hero (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output This is an easy version of the problem. It differs from the hard one only by constraints on n and t . There is a deck of n cards, each of which is characterized by its power. There are two types of cards: a hero card, the power of such a card is always equal to 0 ; a bonus card, the power of such a card is always positive. You can do the following with the deck: take a card from the top of the deck; if this card is a bonus card, you can put it on top of your bonus deck or discard; if this card is a hero card, then the power of the top card from your bonus deck is added to his power (if it is not empty), after that the hero is added to your army, and the used bonus discards. Your task is to use such actions to gather an army with the maximum possible total power. Input The first line of input data contains single integer t (1≤t≤1000 ) — the number of test cases in the test. The first line of each test case contains one integer n (1≤n≤5000 ) — the number of cards in the deck. The second line of each test case contains n integers s1,s2,…,sn (0≤si≤109 ) — card powers in top-down order. It is guaranteed that the sum of n over all test cases does not exceed 5000 . Output Output t numbers, each of which is the answer to the corresponding test case — the maximum possible total power of the army that can be achieved.
最新发布
03-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值