-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemStmt-0b.cpp
More file actions
118 lines (116 loc) · 1.84 KB
/
ProblemStmt-0b.cpp
File metadata and controls
118 lines (116 loc) · 1.84 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long n,i,j,k;
cin>>n;
long long a[n],c[n],d[n];
for(i=0;i<n;i++){
cin>>a[i];
c[i]=a[i];
d[i]=c[i];//d[i] is the original
}
int q;
cin>>q;
int b[q];
for(i=0;i<q;i++)
cin>>b[i];
/*cout<<"Shoba"<<endl;
//possibility 1(if the exact length is present,give it to the customer, else do not give him anything(sample i/o logic says so)
for(j=0;j<q;j++){
for(i=0;i<n;i++){
if(b[j]==a[i]){
a[i]=0;
i=n+3;
}
}
if(i!=(n+4))
cout<<"-1";
else{
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
cout<<endl;
}*/
for(i=0;i<n;i++)
a[i]=d[i];
//possibility 2-difference in logic between problem statement and sample i/o
cout<<"Shoba"<<endl;
//possibility 2(problem statement-start from the top , keep reducing as you find)
for(j=0;j<q;j++){
for(i=0;i<n;i++){
if(b[j]<=a[n-i-1]){
a[n-i-1]=a[n-i-1]-b[j];
i=n+3;
}
}
if(i!=n+4){
cout<<"-1";
}
else
{
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
cout<<endl;
}
for(i=0;i<n;i++)
a[i]=d[i];
cout<<"Kamal"<<endl;
for(j=0;j<q;j++){
for(i=0;i<n;i++)
c[i]=a[i];
sort(c,c+n);
for(i=0;i<n;i++){
if(b[j]==c[i]){
k=c[i];
i=n+3;
}
if((i<(n-1))&&(i!=(n+3))){
if((b[j]>c[i])&&(b[j]<c[i+1])){
k=c[i+1];
i=n+3;
}
}
}
if(i!=n+4){
cout<<"-1";
}
else
{
for(i=0;i<n;i++){
if(k==a[i])
a[i]=k-b[j];
}
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
cout<<endl;
}
for(i=0;i<n;i++)
a[i]=d[i];
cout<<"Jasmine"<<endl;
for(j=0;j<q;j++){
for(i=0;i<n;i++)
c[i]=a[i];
sort(c,c+n);
for(i=0;i<n;i++){
if(c[n-i-1]>=b[j]){
k=c[n-i-1];
i=n+3;
}
}
if(i!=n+4){
cout<<"-1";
}
else{
for(i=0;i<n;i++){
if(k==a[i])
a[i]=k-b[j];
}
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
cout<<endl;
}
}