Skip to content

Commit 43c89f6

Browse files
authored
Merge branch 'main' into main
2 parents 7475146 + 6315398 commit 43c89f6

6 files changed

Lines changed: 259 additions & 0 deletions

File tree

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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//https://codeforces.com/contest/1560/submission/355205808
2+
//time complexity:O(t)
3+
//space complexity:O(1)
4+
#include <iostream>
5+
using namespace std;
6+
7+
int main()
8+
{
9+
int t;
10+
cin>>t;
11+
while(t--){
12+
int a,b,c;
13+
cin>>a>>b>>c;
14+
int len;
15+
if(a>b){
16+
len=a-b;
17+
len=2*len;
18+
} // staring at opposite end means both of them divide the circle
19+
// in exact half so we substract them and multiply by 2 to get exact length
20+
else {
21+
22+
len=b-a;
23+
len=2*len;
24+
25+
}
26+
if(a<=len&&b<=len&&c<=len){//a,b,c ofcourse cannot be greater than length
27+
if(c+(len/2)>len){
28+
cout<<c-(len/2)<<endl;//c will either stare at +n/2 or -n/2
29+
}
30+
else{
31+
cout<<c+(len/2)<<endl;
32+
}
33+
}
34+
else{cout<<-1<<endl;}
35+
}
36+
37+
return 0;
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define int long long int
4+
#define double long double
5+
#define endl '\n'
6+
void resolve() {
7+
int a,b,c,d=0;
8+
cin>>a>>b>>c;
9+
int n = 2*abs(b-a);
10+
if(b>n || c>n || a>n)
11+
d = -1;
12+
else
13+
{
14+
if(c<=(n/2))
15+
d = c + n/2;
16+
else
17+
d = c - n/2;
18+
19+
if(d==a || d==b || d>n || d<1)
20+
d=-1;
21+
}
22+
cout<<d<<endl;
23+
}
24+
int32_t main() {
25+
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
26+
int t;
27+
cin >> t;
28+
while(t--)
29+
resolve();
30+
return 0;
31+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Problem Description
2+
3+
Masha works in an advertising agency. In order to promote a new brand, she wants to conclude contracts with some bloggers.
4+
5+
Masha has connections with `n` different bloggers. Blogger numbered `i` has `ai` followers.
6+
7+
Due to a limited budget, Masha can only sign contracts with `k` different bloggers. She wants the advertisement to be seen by as many people as possible, so she must choose bloggers such that the **total number of followers is maximized**.
8+
9+
Your task is to find the **number of ways** to select `k` bloggers so that the total number of their followers is maximum possible.
10+
11+
Two ways are considered different if there is at least one blogger selected in one way but not in the other.
12+
13+
---
14+
15+
## Input Format
16+
17+
- The first line contains an integer `t` — the number of test cases.
18+
- For each test case:
19+
- The first line contains two integers `n` and `k`
20+
- The second line contains `n` integers `a1, a2, ..., an`, where `ai` is the number of followers of the `i`-th blogger
21+
22+
---
23+
24+
## Output Format
25+
26+
- For each test case, print a single integer — the number of ways to select `k` bloggers such that the total number of followers is maximum possible.
27+
- Since the answer can be large, print it modulo `10^9 + 7`.
28+
29+
---
30+
31+
32+
33+
## Constraints
34+
35+
- `1 ≤ t ≤ 1000`
36+
- `1 ≤ k ≤ n ≤ 1000`
37+
- `1 ≤ ai ≤ n`
38+
- The sum of `n` over all test cases does not exceed `1000`
39+
40+
---
41+
42+
## Sample Input
43+
44+
```
45+
3
46+
4 3
47+
1 3 1 2
48+
4 2
49+
1 1 1 1
50+
2 1
51+
1 2
52+
```
53+
---
54+
55+
## Output
56+
57+
```
58+
2
59+
6
60+
1
61+
```
62+
63+
---
64+
65+
### Additional Resource
66+
67+
For understanding **modular arithmetic and modular inverses**, which are useful for solving problems with answers modulo `10^9+7`, you can check this video:
68+
https://youtu.be/RCq5TYMZEwg
69+
70+
---
71+
72+
73+
[PROBLEM LINK](http://codeforces.com/contest/1475/problem/E)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Problem Description
2+
3+
You are given a single integer `N`.
4+
5+
You are asked to compute the following summation:
6+
7+
Σ(i=1 to N) Σ(j=1 to N) Σ(k=1 to i) Σ(l=1 to j) (gcd(k, i) × gcd(l, j) × gcd(i, j))
8+
9+
Output the value of this summation **modulo 1000000007**.
10+
11+
---
12+
13+
## Input Format
14+
15+
- The input consists of a single integer `N`.
16+
17+
---
18+
19+
## Output Format
20+
21+
- Output the value of the summation modulo `1000000007`.
22+
23+
---
24+
25+
## Constraints
26+
27+
- 1 ≤ N ≤ 10^6
28+
29+
---
30+
31+
32+
## Sample Input 1
33+
34+
```
35+
2
36+
```
37+
---
38+
39+
## Output
40+
41+
```
42+
25
43+
```
44+
---
45+
46+
## Sample Input 2
47+
48+
```
49+
8
50+
```
51+
---
52+
53+
## Output
54+
55+
```
56+
13348
57+
```
58+
---
59+
60+
[PROBLEM LINK](https://www.codechef.com/problems/YETGCD?tab=statement)

contributers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@
4545
| Ronak Goyal | ronakgoyal1 | IIIT Allahabad |
4646
| Sayed Al Amaan Zaidi | amaan1114 | Rishihood University |
4747
|Aditya Singh | adityasingh-0803 | BVDUCOEP |
48+
| Ishan Raj Singh | ishanrajsingh | Amity, Noida
49+
|Priyanshi Giri | hellopaintinghi-cmd | IIIT Allahabad |
4850
| Mahavir dodiya |Mvdodiya001 | IIIT Allahabad |
4951
| Ishan Raj Singh | ishanrajsingh | Amity, Noida |
52+
| Harsh Garg | gargharsh182005-lab | IIIT Allahabad |
5053
| Lakshmish | Coldesy | IIIT Allahabad
5154
|Priyanshu Ranjan | justpriyanshu | BIT Mesra
5255
| Vrajkumar Shah | vraj826 | DDU, Nadiad
56+
| Atharva Mehta | Atharva-insane | IIIT Allahabad |
5357
<!-- ADD ABOVE THIS -->
5458
<!-- example | Korvac | Betty | Reyansh College | -->

0 commit comments

Comments
 (0)