Skip to content

Commit

Permalink
✅ greddy, sortings
Browse files Browse the repository at this point in the history
  • Loading branch information
iagorrr committed Nov 21, 2023
1 parent c435e72 commit c7c3224
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions submissions/Codeforces/1899E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.cpp"
#else
#define dbg(...) 42
#endif
#define endl '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define len(__x) (int)__x.size()
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using vll2d = vector<vll>;
using vi = vector<int>;
using vi2d = vector<vi>;
using pii = pair<int, int>;
using vii = vector<pii>;
using vc = vector<char>;
#define all(a) a.begin(), a.end()
#define pb(___x) push_back(___x)
#define mp(___a, ___b) make_pair(___a, ___b)
#define eb(___x) emplace_back(___x)
int lg2(ll x) {
return __builtin_clzll(1) - __builtin_clzll(x);
}

// vector<string> dir({"LU", "U", "RU", "R", "RD", "D",
// "LD", "L"}); int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int
// dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
vector<string> dir({"U", "R", "D", "L"});
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

const ll oo = 1e18;
int T(1);

auto solve() {
int n;
cin >> n;

vi xs(n);
for (int i = 0; i < n; i++) {
cin >> xs[i];
}

int mpos = min_element(all(xs)) - xs.begin();

for (int i = mpos; i < n - 1; i++) {
if (xs[i] > xs[i + 1]) return -1;
}

return mpos;
}

int32_t main(void) {
#ifndef LOCAL
fastio;
#endif

cin >> T;

for (int i = 1; i <= T; i++) {
cout << solve() << endl;
}
}

// AC, greedy, sortings

0 comments on commit c7c3224

Please sign in to comment.