done 3 sorting problems
This commit is contained in:
36
CSES - CSES Problem Set/Apartments.cpp
Normal file
36
CSES - CSES Problem Set/Apartments.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Apartments
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
using ll = long long;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
ll k; cin >> n >> m >> k;
|
||||
vector<ll> as(n);
|
||||
for (auto &e: as) cin >> e;
|
||||
vector<ll> bs(m);
|
||||
for (auto &e: bs) cin >> e;
|
||||
std::sort(as.begin(), as.end(), greater<ll>());
|
||||
std::sort(bs.begin(), bs.end(), greater<ll>());
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (as.size()) {
|
||||
int val = as.back();
|
||||
as.pop_back();
|
||||
while (bs.size()) {
|
||||
int val2 = bs.back();
|
||||
if (val2 > val + k) break;
|
||||
bs.pop_back();
|
||||
if (val2 + k >= val && val2 - k <= val) {
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
19
CSES - CSES Problem Set/Distinct_Numbers.cpp
Normal file
19
CSES - CSES Problem Set/Distinct_Numbers.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Distinct Numbers
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int count = 1;
|
||||
int n; cin >> n;
|
||||
vector<ll> i(n);
|
||||
for (auto &e: i) cin >> e;
|
||||
std::sort(i.begin(), i.end());
|
||||
for (int j = 1; j < i.size(); j++) {
|
||||
if (i[j] != i[j-1]) count ++;
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
29
CSES - CSES Problem Set/Ferris_Wheel.cpp
Normal file
29
CSES - CSES Problem Set/Ferris_Wheel.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// Ferris Wheel
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
ll n; cin >> n;
|
||||
ll x; cin >> x;
|
||||
vector<ll> ps(n);
|
||||
for (auto &e: ps) cin >> e;
|
||||
ll count = 0;
|
||||
ll min = 0;
|
||||
ll max = n-1;
|
||||
std::sort(ps.begin(), ps.end());
|
||||
while (min <= max) {
|
||||
if (ps[min] + ps[max] <= x) {
|
||||
max--;
|
||||
min++;
|
||||
count++;
|
||||
} else {
|
||||
max --;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user