-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path683C.cpp
More file actions
74 lines (67 loc) · 1.81 KB
/
Copy path683C.cpp
File metadata and controls
74 lines (67 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
ll n, w;
scanf("%lld %lld", &n, &w);
ll cumu[n];
vector<pair<ll,ll>>arr;
ll a;
for (int i = 0; i < n; i++)
{
scanf("%lld", &a);
arr.push_back(make_pair(a,i));
}
sort(arr.begin(),arr.end());
ll arr2[n+1];
arr2[0] = arr[0].first;
cumu[0] = arr[0].first;
// for (int i = 0; i < n; i++)
// {
// printf("%lld ",arr[i].first);
// }
for (int i = 1; i < n; i++)
{
cumu[i] = arr[i].first+cumu[i-1];
arr2[i] = arr[i].first;
}
arr.push_back(make_pair(10000000000000000009,n));
arr2[n] = arr[n].first;
// printf("%lld\n",arr[1].first);
int c1 = (w+1)/2;
int ans = 0;
int idx = lower_bound(arr2,arr2+n+1,c1) - arr2;
// printf("%d\n",idx);
// printf("%lld\n",arr2[0]);
if(arr2[idx] <= w && idx != n){
// printf("%d\n",idx);
printf("1\n");
printf("%lld\n",arr[idx].second+1);
}
else
{
bool yes = false;
for (int i = 0; i < n; i++)
{
if(cumu[i] <= w && cumu[i] >= c1){
printf("%d\n",i+1);
for (int j = 0; j <= i; j++)
{
printf("%lld ",arr[j].second+1);
}
printf("\n");
yes = true;
break;
}
}
if(!yes){
printf("-1\n");
}
}
}
}