-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquestion21.c
51 lines (44 loc) · 911 Bytes
/
question21.c
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
/*
http://practice.geeksforgeeks.org/problems/tricky-subset-problem/0
*/
#include <stdio.h>
int canBeFormed(int *arr, int *ref, int n, int s, int x){
ref[0] = s;
int temp = s;
int i;
for(i=1;i<n;i++){
ref[i] = temp + arr[i];
temp = temp + ref[i];
if(x < ref[i]){
break;
}
}
int j,k;
for(j=i-1;j>=0;j--){
if(x-ref[j] > 0){
x = x - ref[j];
}
for(k = 0; k<=j;k++){
if(x == ref[k]){
return 1;
break;
}
}
}
return 0;
}
int main(){
int cases;
scanf("%d",&cases);
while(cases>0){
int s,n,x;
scanf("%d %d %d",&s,&n,&x);
int arr[100000], ref[100000];
if(canBeFormed(arr,ref,s,n,x)){
printf("yes\n");
}else{
printf("no\n");
}
cases--;
}
}