Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: B. Milena and Admirer
- // Contest: Codeforces - Codeforces Round 910 (Div. 2)
- // URL: https://codeforces.com/problemset/problem/1898/B
- // Memory Limit: 256 MB
- // Time Limit: 1000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- void solve1()
- {
- ll n;
- cin >> n;
- vl a(n);
- for (auto &x : a)
- cin >> x;
- reverse(a.begin(), a.end());
- ll op = 0;
- for (ll i = 0, prev = a[0]; i < n; ++i) {
- if (a[i] > prev) {
- if (a[i] % prev == 0) {
- op += a[i] / prev - 1;
- } else {
- if (a[i] >= 2 * prev - 1) {
- if (i == n - 1) {
- op += (a[i] + prev - 1) / prev - 1;
- } else {
- op += (a[i] + prev - a[i] % prev) / prev - 1;
- prev = prev - 1;
- }
- } else {
- op += 1;
- prev = a[i] / 2;
- }
- }
- } else {
- prev = a[i];
- }
- }
- cout << op << '\n';
- }
- void solve2()
- {
- ll n;
- cin >> n;
- vl a(n);
- for (auto &x : a)
- cin >> x;
- reverse(a.begin(), a.end());
- ll op = 0;
- for (ll i = 0, prev = a[0]; i < n; ++i) {
- if (a[i] <= prev) {
- a[i] = prev;
- } else {
- ll t = (a[i] + prev - 1) / prev;
- prev = a[i] / t;
- op += t - 1;
- }
- }
- cout << op << '\n';
- }
- void solve()
- {
- ll n;
- cin >> n;
- vl a(n);
- for (auto &x : a)
- cin >> x;
- reverse(a.begin(), a.end());
- ll op = 0;
- for (ll i = 0; i + 1 < n; ++i) {
- if (a[i] < a[i + 1]) {
- ll y = ((a[i + 1] + a[i] - 1) / a[i]);
- a[i + 1] = a[i + 1] / y;
- op += y - 1;
- }
- }
- cout << op << '\n';
- }
- int main(int argc, char **argv)
- {
- ll t;
- cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement