A. Anti-knapsack  Codeforces Round #705 (Div. 2)

A. Anti-knapsack  Codeforces Round #705 (Div. 2)

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two integers nn and kk. You are asked to choose maximum number of distinct integers from 11 to nn so that there is no subset of chosen numbers with sum equal to kk.

A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.

Input

The first line contains the number of test cases TT (1≤T≤1001≤T≤100).

Each of the next TT lines contains two integers nn and kk (1≤k≤n≤10001≤k≤n≤1000) — the description of test cases.

Output

For each test case output two lines. In the first line output a single integer mm — the number of chosen integers.

In the second line output mm distinct integers from 11 to nn — the chosen numbers.

If there are multiple answers, print any. You can print the numbers in any order.

Example

input

Copy

3
3 2
5 3
1 1

output

Copy

2
3 1 
3
4 5 2 
0

题目大意:从1到n中找出一个集合,该集合的子集相加不能等于k。

解题思路:大于k必定符合题意,取到的数必达于k,小于k的取到(k + 1) / 2 ,(当k == 6时,小于6的不能取2,因为2 + 4等于6).

AC代码:

#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
 
#define ll long long
#define INF 0x3f3f3f3f;
 
int main() {
    int t;
    cin >> t;
    while (t--) {
        int s, e;
        cin >> s >> e;
        int cnt = 0;
        vector<int>a;
        for (int i = e+1; i <= s; i++) {
            a.push_back(i);
            cnt++;
        }
        for (int i = e - 1; i >= (e + 1) / 2; i--){
            a.push_back(i);
            cnt++;
        }
        //if (e == 2) {a.push_back(1);cnt++;}
        cout << cnt << '\n';
        if (cnt!=0){
            cout << a[0];
        for (int i = 1; i < a.size();i++) {
            cout << " " << a[i];
        }
            cout << "\n";
        }
    }
 
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值