aboutsummaryrefslogtreecommitdiff
path: root/contests/Round#809/A/B/main.cpp
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-07-24 13:11:33 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-07-24 13:11:33 +0300
commit6b548332bfc6469756526002971c422f43f86d0a (patch)
tree261fde23f07c3e20cea375030f0c52863b59228c /contests/Round#809/A/B/main.cpp
parentcff8cae22ee9c25d193ff976143813f93e658e55 (diff)
downloadcompetitive-programming-6b548332bfc6469756526002971c422f43f86d0a.tar.xz
competitive-programming-6b548332bfc6469756526002971c422f43f86d0a.zip
Removed some empty *.cpp files and Solved some new problems
Diffstat (limited to 'contests/Round#809/A/B/main.cpp')
-rwxr-xr-xcontests/Round#809/A/B/main.cpp58
1 files changed, 0 insertions, 58 deletions
diff --git a/contests/Round#809/A/B/main.cpp b/contests/Round#809/A/B/main.cpp
deleted file mode 100755
index 90c55c2..0000000
--- a/contests/Round#809/A/B/main.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <bits/stdc++.h>
-
-using namespace std;
-
-bool isCool(vector<int> &a, int i) {
- if (i == 0) {
- return false;
- }
- if (a[i - 1] < a[i] && a[i + 1] < a[i]) {
- return true;
- }
- return false;
-}
-
-int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int tt;
- cin >> tt;
- while (tt--) {
- int n;
- cin >> n;
- vector<int> a(n);
- for (int &x : a)
- cin >> x;
- long long ans = 0;
- long long mx = 0;
- int max_cool = (n - 1) / 2;
- int cnt = 0;
- if(n > 3) {
- for (int i = 1; i < n - 1; i++) {
- if(isCool(a,i)) {
- cnt++;
- }
- if (!isCool(a, i) && i % 2 == 0) {
- ans += abs(a[i] - max(a[i - 1], a[i + 1])) + 1;
- } else if(!isCool(a, i) && i % 2 != 0) {
- mx += abs(a[i] - max(a[i - 1], a[i + 1])) + 1;
- }
- }
- long long mx2 = 0;
- for (int i = 1; i < n - 1; i += 3) {
- if (!isCool(a, i)) {
- mx2 += abs(a[i] - max(a[i - 1], a[i + 1])) + 1;
- }
- }
- cerr << mx << " " << ans << " " << mx2 << endl;
- if(cnt < max_cool) {
- // cout << max(mx2, max(ans, mx)) << endl;
- } else {
- cout << min(mx2, min(ans, mx)) << endl;
- }
-
- } else {
- cout << abs(a[1] - max(a[0], a[2])) + 1 << endl;
- }
- }
-}