Submission #213074

# Submission time Handle Problem Language Result Execution time Memory
213074 2020-03-25T00:55:49 Z qkxwsm Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
250 ms 15336 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 500013;
const int INF = 1000000007;

int N;
ll arr[MAXN];
ll net[MAXN];
ll ans;
vl vec;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    FOR(i, 1, N + 1)
    {
        int a, b;
        cin >> a >> b;
        arr[i] = a - b;
    }
    //you want to make everything >= 0, and you can move smth 1 left or 1 right at a time.
    //+1 -1 => +1 +0
    //-1 +1 => -1 +0
    FOR(i, 1, N + 1)
    {
        arr[i] += arr[i - 1];
    }
    FOR(i, 1, N)
    {
        if (arr[i] < 0)
        {
            ans -= arr[i];
            arr[i] = 0;
        }
        if (arr[i] > arr[N])
        {
            ans += (arr[i] - arr[N]);
            arr[i] = arr[N];
        }
        ans += arr[i];
    }
    priority_queue<ll> pq;
    FOR(i, 1, N)
    {
        pq.push(arr[i]);
        pq.push(arr[i]);
        pq.pop();
    }
    while(!pq.empty())
    {
        ans -= (pq.top());
        pq.pop();
    }
    //make the sequence increasing. or equal. in each move you can change smth by 0 or 1.
    cout << ans << '\n';
    return 0;
    //make all arr's positive, what's the cost?

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 16 ms 1792 KB Output is correct
5 Correct 28 ms 2940 KB Output is correct
6 Correct 83 ms 7920 KB Output is correct
7 Correct 181 ms 15208 KB Output is correct
8 Correct 166 ms 13420 KB Output is correct
9 Correct 158 ms 12780 KB Output is correct
10 Correct 137 ms 10476 KB Output is correct
11 Correct 134 ms 10476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 16 ms 1792 KB Output is correct
5 Correct 28 ms 2940 KB Output is correct
6 Correct 83 ms 7920 KB Output is correct
7 Correct 181 ms 15208 KB Output is correct
8 Correct 166 ms 13420 KB Output is correct
9 Correct 158 ms 12780 KB Output is correct
10 Correct 137 ms 10476 KB Output is correct
11 Correct 134 ms 10476 KB Output is correct
12 Correct 47 ms 4184 KB Output is correct
13 Correct 114 ms 10988 KB Output is correct
14 Correct 188 ms 15212 KB Output is correct
15 Correct 164 ms 13420 KB Output is correct
16 Correct 158 ms 12780 KB Output is correct
17 Correct 142 ms 10480 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 16 ms 1792 KB Output is correct
12 Correct 28 ms 2940 KB Output is correct
13 Correct 83 ms 7920 KB Output is correct
14 Correct 181 ms 15208 KB Output is correct
15 Correct 166 ms 13420 KB Output is correct
16 Correct 158 ms 12780 KB Output is correct
17 Correct 137 ms 10476 KB Output is correct
18 Correct 134 ms 10476 KB Output is correct
19 Correct 47 ms 4184 KB Output is correct
20 Correct 114 ms 10988 KB Output is correct
21 Correct 188 ms 15212 KB Output is correct
22 Correct 164 ms 13420 KB Output is correct
23 Correct 158 ms 12780 KB Output is correct
24 Correct 142 ms 10480 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 66 ms 4212 KB Output is correct
33 Correct 153 ms 11040 KB Output is correct
34 Correct 247 ms 15208 KB Output is correct
35 Correct 250 ms 12900 KB Output is correct
36 Correct 188 ms 13376 KB Output is correct
37 Correct 249 ms 15336 KB Output is correct
38 Correct 157 ms 11500 KB Output is correct
39 Correct 176 ms 10988 KB Output is correct
40 Correct 154 ms 10524 KB Output is correct
41 Correct 143 ms 10476 KB Output is correct
42 Correct 147 ms 10500 KB Output is correct
43 Correct 142 ms 10476 KB Output is correct
44 Correct 203 ms 15212 KB Output is correct
45 Correct 170 ms 10876 KB Output is correct
46 Correct 152 ms 10348 KB Output is correct
47 Correct 5 ms 384 KB Output is correct