Skip to content

Commit 15d191f

Browse files
Merge branch 'main' of https://github.com/opencodeiiita/CP-Chronicles into day2-q001
2 parents 75b4cd6 + 6d8d4e3 commit 15d191f

93 files changed

Lines changed: 6482 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

2 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

Problems/.DS_Store

6 KB
Binary file not shown.

Problems/Mathematics/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
14 KB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
/*
4+
Logic:
5+
The main key in solving the problem is that a,b will be enought to know that the size of the area.
6+
Another observation would be that 1 is always facing the element more than the element which faces
7+
at the last element or the size of the circle.
8+
Once, you get the size of the array, we just have to check if the any of the elements are larger than
9+
the size of the array.
10+
On deeper checks like- a=3, b=2,c=1;
11+
we can observe how this isn't true but how does the conditon fulfill the case?
12+
--> the max check covers all small checks, like the circle don being possible
13+
in cases like a=1,b=6, c=100
14+
--> the circle condition is also checked by the max case.
15+
16+
So, after the checking, we need to see the answer, that can be easily given as the
17+
difference is same for all pairs of elements modular nature of the circle( cool words that make sense)
18+
19+
Time complexity-->
20+
21+
The time complexity is O(1)
22+
The space complexity is O(1)
23+
24+
Submission link- https://codeforces.com/contest/1560/submission/355188467
25+
*/
26+
//Soln->
27+
int main() {
28+
ios::sync_with_stdio(false);
29+
cin.tie(nullptr);
30+
31+
int t;
32+
cin >> t;
33+
34+
while (t--) {
35+
int a,b,c;
36+
cin>>a;
37+
cin>>b;
38+
cin>>c;
39+
int x=abs(b-a);
40+
if(max({a,b,c})>(2*x))
41+
cout<<-1<<endl;
42+
else
43+
{
44+
if(c>x)
45+
cout<<c-x<<endl;
46+
else
47+
cout<<c+x<<endl;
48+
}
49+
50+
}
51+
return 0;
52+
}
53+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* 1 to n people are standing in a circle. n is even.... a is looking at b.
2+
If given c is looking at some d person for given a,b then find that d. If such a combination
3+
of circle does not exist then print -1*/
4+
5+
// Time complexity: O(1)
6+
// Space complexity: O(1)
7+
//My submission: https://codeforces.com/contest/1560/submission/355204246
8+
9+
#include <bits/stdc++.h>
10+
using namespace std;
11+
12+
using ll = long long;
13+
#define all(x) (x).begin(), (x).end()
14+
15+
const int MOD = 1e9 + 7; // 998244353
16+
const ll INF = 1e18;
17+
18+
void solve() {
19+
int a,b,c;
20+
cin>>a>>b>>c;
21+
int n=2*abs(a-b);
22+
if(a>n || b>n ||c>n ) cout<<-1<<endl;
23+
else{
24+
int x=c-n/2,y=c+n/2;
25+
if(x>=1 && x<=n) cout<<x<<endl;
26+
else cout<<y<<endl;
27+
}
28+
}
29+
30+
int main() {
31+
// Fast I/O
32+
ios::sync_with_stdio(false);
33+
cin.tie(nullptr);
34+
35+
int t;
36+
cin >> t;
37+
while (t--) {
38+
solve();
39+
}
40+
41+
return 0;
42+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//https://codeforces.com/contest/1560/problem/C
2+
//https://codeforces.com/contest/1560/submission/355210608
3+
// TC : O(1) SC: O(1)
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
int main() {
8+
int t;
9+
cin>>t;
10+
while(t--){
11+
int a,b,c;
12+
cin>>a>>b>>c;
13+
int k=abs(a-b);
14+
if(a>2*k || b>2*k || c>2*k){
15+
cout<<-1<<endl;
16+
}
17+
else{
18+
if((c-k)>0){
19+
cout<<c-k<<endl;
20+
}
21+
else{
22+
cout<<c+k<<endl;
23+
}
24+
}
25+
}
26+
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int t;
6+
cin >> t;
7+
8+
while (t--) {
9+
int a, b, c;
10+
cin >> a >> b >> c;
11+
12+
int half = abs(a - b);
13+
int n = 2 * half;
14+
15+
if (c > n) {
16+
cout << -1 << "\n";
17+
} else {
18+
int opposite = (c + half <= n) ? (c + half) : (c - half);
19+
cout << opposite << "\n";
20+
}
21+
}
22+
return 0;
23+
}

0 commit comments

Comments
 (0)