From 51c35987f270f7a19d83a11b2427a9ff7803e17c Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Fri, 15 Jul 2022 18:34:14 +0200 Subject: Solved a couple of problems on codeforces --- MarkTheDustSweeper/main | Bin 0 -> 27320 bytes MarkTheDustSweeper/main.cpp | 39 +++++++++++++++++++++++++++++++++++ MarkTheDustSweeper/main_input0.txt | 9 ++++++++ MarkTheDustSweeper/main_output0.txt | 4 ++++ MarkThePhotographer/main | Bin 0 -> 44912 bytes MarkThePhotographer/main.cpp | 31 ++++++++++++++++++++++++++++ MarkThePhotographer/main_input0.txt | 7 +++++++ MarkThePhotographer/main_output0.txt | 3 +++ yapapsai/main | Bin 0 -> 32512 bytes yapapsai/main.cpp | 26 +++++++++++++++++++++++ yapapsai/main_input0.txt | 11 ++++++++++ yapapsai/main_output0.txt | 5 +++++ 12 files changed, 135 insertions(+) create mode 100755 MarkTheDustSweeper/main create mode 100644 MarkTheDustSweeper/main.cpp create mode 100644 MarkTheDustSweeper/main_input0.txt create mode 100644 MarkTheDustSweeper/main_output0.txt create mode 100755 MarkThePhotographer/main create mode 100644 MarkThePhotographer/main.cpp create mode 100644 MarkThePhotographer/main_input0.txt create mode 100644 MarkThePhotographer/main_output0.txt create mode 100755 yapapsai/main create mode 100644 yapapsai/main.cpp create mode 100644 yapapsai/main_input0.txt create mode 100644 yapapsai/main_output0.txt diff --git a/MarkTheDustSweeper/main b/MarkTheDustSweeper/main new file mode 100755 index 0000000..0ceccde Binary files /dev/null and b/MarkTheDustSweeper/main differ diff --git a/MarkTheDustSweeper/main.cpp b/MarkTheDustSweeper/main.cpp new file mode 100644 index 0000000..6335886 --- /dev/null +++ b/MarkTheDustSweeper/main.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n; + cin >> n; + long long ans = 0; + vector v(n); + long long sum = 0; + for (auto &x : v) { + cin >> x; + sum += x; + } + if(sum != v[n - 1]) { + int ind; + for(int i = 0; i < n; i++) { + if(v[i] != 0) { + ind = i; + break; + } + } + for(int i = ind; i < n - 1; i++) { + if(v[i] == 0) { + ans += 1; + } else{ + ans += v[i]; + } + } + } + cout << ans << endl; + } +} diff --git a/MarkTheDustSweeper/main_input0.txt b/MarkTheDustSweeper/main_input0.txt new file mode 100644 index 0000000..ad05cd8 --- /dev/null +++ b/MarkTheDustSweeper/main_input0.txt @@ -0,0 +1,9 @@ +4 +3 +2 0 0 +5 +0 2 0 2 0 +6 +2 0 3 0 4 6 +4 +0 0 0 10 diff --git a/MarkTheDustSweeper/main_output0.txt b/MarkTheDustSweeper/main_output0.txt new file mode 100644 index 0000000..0c8b213 --- /dev/null +++ b/MarkTheDustSweeper/main_output0.txt @@ -0,0 +1,4 @@ +3 +5 +11 +0 diff --git a/MarkThePhotographer/main b/MarkThePhotographer/main new file mode 100755 index 0000000..eaaf214 Binary files /dev/null and b/MarkThePhotographer/main differ diff --git a/MarkThePhotographer/main.cpp b/MarkThePhotographer/main.cpp new file mode 100644 index 0000000..15c4e29 --- /dev/null +++ b/MarkThePhotographer/main.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + int n, y; + cin >> n >> y; + vector v(2 * n); + int ans = 0; + for (int &x : v) + cin >> x; + sort(v.begin(), v.end()); + for (int i = 0; i < n; i++) { + int x = v[i]; + int z = v[i + n]; + if (z - x >= y) { + ans++; + } + } + if (ans == n) { + cout << "YES" << '\n'; + } else { + cout << "NO" << '\n'; + } + } +} diff --git a/MarkThePhotographer/main_input0.txt b/MarkThePhotographer/main_input0.txt new file mode 100644 index 0000000..3e55cb5 --- /dev/null +++ b/MarkThePhotographer/main_input0.txt @@ -0,0 +1,7 @@ +3 +3 6 +1 3 9 10 12 16 +3 1 +2 5 2 2 2 5 +1 2 +8 6 diff --git a/MarkThePhotographer/main_output0.txt b/MarkThePhotographer/main_output0.txt new file mode 100644 index 0000000..0db7433 --- /dev/null +++ b/MarkThePhotographer/main_output0.txt @@ -0,0 +1,3 @@ +YES +NO +YES diff --git a/yapapsai/main b/yapapsai/main new file mode 100755 index 0000000..a26e653 Binary files /dev/null and b/yapapsai/main differ diff --git a/yapapsai/main.cpp b/yapapsai/main.cpp new file mode 100644 index 0000000..2946e65 --- /dev/null +++ b/yapapsai/main.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n; + cin >> n; + vector pos; + long long ans = 0; + for (int i = 1; i <= n; i++) { + int x; + cin >> x; + if (x < i) { + auto it = lower_bound(pos.begin(), pos.end(), x); + ans += it - pos.begin(); + pos.emplace_back(i); + } + } + cout << ans << '\n'; + } +} diff --git a/yapapsai/main_input0.txt b/yapapsai/main_input0.txt new file mode 100644 index 0000000..bb1b141 --- /dev/null +++ b/yapapsai/main_input0.txt @@ -0,0 +1,11 @@ +5 +8 +1 1 2 3 8 2 1 4 +2 +1 2 +10 +0 2 1 6 3 4 1 2 8 3 +2 +1 1000000000 +3 +0 1000000000 2 diff --git a/yapapsai/main_output0.txt b/yapapsai/main_output0.txt new file mode 100644 index 0000000..5859aa7 --- /dev/null +++ b/yapapsai/main_output0.txt @@ -0,0 +1,5 @@ +3 +0 +10 +0 +1 -- cgit v1.2.3