Shashlik Cooking(思维题)

https://cn.vjudge.net/problem/CodeForces-1040B

Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.

This time Miroslav laid out nn skewers parallel to each other, and enumerated them with consecutive integers from 11 to nn in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number ii, it leads to turning kk closest skewers from each side of the skewer ii, that is, skewers number i−ki−k, i−k+1i−k+1, ..., i−1i−1, i+1i+1, ..., i+k−1i+k−1, i+ki+k (if they exist).

For example, let n=6n=6 and k=1k=1. When Miroslav turns skewer number 33, then skewers with numbers 22, 33, and 44 will come up turned over. If after that he turns skewer number 11, then skewers number 11, 33, and 44 will be turned over, while skewer number 22will be in the initial position (because it is turned again).

As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all nn skewers with the minimal possible number of actions. For example, for the above example n=6n=6 and k=1k=1, two turnings are sufficient: he can turn over skewers number 22 and 55.

Help Miroslav turn over all nn skewers.

Input

The first line contains two integers nn and kk (1≤n≤10001≤n≤1000, 0≤k≤10000≤k≤1000) — the number of skewers and the number of skewers from each side that are turned in one step.

Output

The first line should contain integer ll — the minimum number of actions needed by Miroslav to turn over all nn skewers. After than print ll integers from 11 to nndenoting the number of the skewer that is to be turned over at the corresponding step.

Examples

Input

7 2

Output

2
1 6 

Input

5 1

Output

2
1 4 

Note

In the first example the first operation turns over skewers 11, 22 and 33, the second operation turns over skewers 44, 55, 66 and 77.

In the second example it is also correct to turn over skewers 22 and 55, but turning skewers 22 and 44, or 11 and 55 are incorrect solutions because the skewer 33 is in the initial state after these operations.

题意:给出n,k,代表着n个东东(用饼代替)每次可选择一个位置i,那么i-k,i,i+k范围的饼都会被翻转,问选最少的点,是所有的饼都翻转一次,且不能有重复的翻。

思路:只要两端确定了,那么整个序列就确定了,先假设l在1,r在n,那么他们占掉了2*(k+1)个位置,算一算中间有多少个2*k+1,空着的位置通过移动l和r来补,可以保证一定有解,移动l和r可以补最多2*k个位置,而模(2*k+1)的最大值也是2*k,所以一定有解

#include<bits/stdc++.h>
#pragma GCC optimize(3)
#define max(a,b) a>b?a:b
using namespace std;
typedef long long ll;

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int ans=0;
	if(n<=2*k+1){
		printf("1\n");
		printf("%d\n",max(1,n-k));
	}
    else{
    	int m=(n-2*(k+1))/(2*k+1);
    	printf("%d\n",2+m);
    	int p=(n-2*(k+1))%(2*k+1);
    	int l=1,r=n;
    	if(p<=k) r-=p;
    	else{
    		r-=k;
    		p-=k;
    		l+=k;
		}
		for(int i=l;i<=n;i+=2*k+1){
			if(i==r) printf("%d\n",i);
			else printf("%d ",i);
		}
	}
	return 0;
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值