-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
66 lines (65 loc) · 1.48 KB
/
C.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
long long t,n,w,i,sum,count,p;
static long long ara[200005],ans[200005];
cin>>t;
while(t--)
{
sum=0;
count=0;
cin>>n>>w;
for(i=1; i<=n; i++)
cin>>ara[i];
vector <pair<long long,long long>>vect;
for(i=0; i<n; i++)
vect.push_back( make_pair(ara[i+1],i+1) );
sort(vect.begin(), vect.end());
for(i=0; i<n; i++)
{
if(sum+vect[i].first<=w)
{
count++;
sum=sum+vect[i].first;
ans[count]=vect[i].second;
}
else
{
break;
}
}
if(sum>=(w/2+w%2))
{
cout<<count<<"\n";
for(i=1; i<=count; i++)
cout<<ans[i]<<" ";
cout<<"\n";
continue;
}
count=0;
sum=0;
for(i=n-1; i>=0; i--)
{
if(sum+vect[i].first<=w)
{
count++;
sum=sum+vect[i].first;
ans[count]=vect[i].second;
}
}
if(sum>=(w/2+w%2))
{
cout<<count<<"\n";
for(i=1; i<=count; i++)
cout<<ans[i]<<" ";
cout<<"\n";
continue;
}
else
cout<<"-1"<<"\n";
}
return 0;
}