Skip to content

Commit daa4801

Browse files
committed
Adding CSES solution
1 parent c918297 commit daa4801

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

CSES/Apartments.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<bits/stdc++.h>
2+
#include<iostream>
3+
using namespace std;
4+
5+
#define mod 1000000007
6+
#define all(x) (x).begin(), (x).end()
7+
typedef long long ll;
8+
9+
10+
const int mx = 2e5;
11+
int n, m, k, a[mx], b[mx];
12+
13+
void subMain(){
14+
cin >> n >> m >> k;
15+
for(int i = 0; i < n; ++i) cin >> a[i];
16+
for(int i = 0; i < m; ++i) cin >> b[i];
17+
sort(a, a+n);
18+
sort(b, b+m);
19+
int ans = 0;
20+
for(int i = 0, j = 0; i < n; ++i){
21+
while(j < n && b[j] < a[i]-k)
22+
j++;
23+
if(j < n && b[j] <= a[i]+k)
24+
ans++, j++;
25+
}
26+
cout << ans << "\n";
27+
}
28+
29+
int32_t main(){
30+
31+
32+
ios_base::sync_with_stdio(false);
33+
cin.tie(0); cout.tie(0);
34+
35+
/*ll t=1;
36+
cin >> t;
37+
while(t--){
38+
39+
}*/
40+
subMain();
41+
return 0;
42+
}

CSES/Distinct Numbers.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<bits/stdc++.h>
2+
#include<iostream>
3+
using namespace std;
4+
5+
#define mod 1000000007
6+
#define all(x) (x).begin(), (x).end()
7+
typedef long long ll;
8+
9+
10+
11+
void subMain(){
12+
ll n;
13+
cin >> n;
14+
vector<int>a(n);
15+
set<int> s;
16+
for(ll i = 0; i < n; i++){
17+
cin >> a[i];
18+
s.insert(a[i]);
19+
}
20+
cout << s.size() << "\n";
21+
}
22+
23+
int32_t main(){
24+
25+
26+
ios_base::sync_with_stdio(false);
27+
cin.tie(0); cout.tie(0);
28+
29+
/*ll t;
30+
cin >> t;
31+
while(t-- > 0){
32+
subMain();
33+
}*/
34+
subMain();
35+
return 0;
36+
}

CSES/Ferris Wheel.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int n,k;
8+
cin >> n >> k;
9+
int w[n];
10+
for (int i = 0; i < n; i++)
11+
cin >> w[i];
12+
sort(w,w+n);
13+
int l = 0, r = n-1;
14+
int ans = 0;
15+
while (l <= r) {
16+
if (w[l]+w[r] < k+1) l++;
17+
r--;
18+
ans++;
19+
}
20+
cout << ans << endl;
21+
return 0;
22+
}

0 commit comments

Comments
 (0)