Submission #16902

# Submission time Handle Problem Language Result Execution time Memory
16902 2015-10-24T14:28:16 Z erdemkiraz Mountain Trek Route (IZhO12_route) C++
5 / 100
0 ms 9536 KB
#include    <bits/stdc++.h>

using namespace std;

#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

typedef long long ll;
typedef pair < int, int > ii;

const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;

const int N = 2e6 + 5;

int n, k, ans;
int a[N];

int main() {

    scanf("%d %d", &n, &k);

    for(int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }

    for(int i = 0; i < n; i++)
        a[i + n] = a[i];

    set < pair < int, ii > > s;

    for(int i = 0; i < n; i++) {
        int j = i;
        while(j + 1 < 2 * n and a[j + 1] == a[i])
            j++;
        assert(j < n);
        if(!i and a[n - 1] == a[0]) {
            i = j;
            continue;
        }
        int l = (i + n - 1) % n;
        int r = (j + 1) % n;
        if(a[i] < a[l] and a[i] < a[r]) {
            s.insert(make_pair(j - i + 1, ii(i, j)));
        }
        i = j;
    }

    while(s.size()) {
        int len = s.begin() -> first;
        int i = s.begin() -> second.first;
        int j = s.begin() -> second.second;
        int l = (i + n - 1) % n;
        int r = (j + 1) % n;
        if(k < len) {
            break;
        }
        int p = min(k / len, min(a[l], a[r]) - a[i]);
        for(; i <= j; i++) {
            a[i % n] += p;
        }
        k -= p * len;
        ans += p * 2;
        s.erase(s.begin());
    }

    printf("%d\n", ans);

    return 0;

}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 9536 KB gettid (syscall #186) was called by the program (disallowed syscall)
2 Runtime error 0 ms 9536 KB gettid (syscall #186) was called by the program (disallowed syscall)
3 Runtime error 0 ms 9536 KB gettid (syscall #186) was called by the program (disallowed syscall)
4 Correct 0 ms 9536 KB Output is correct
5 Incorrect 0 ms 9536 KB Output isn't correct
6 Incorrect 0 ms 9536 KB Output isn't correct
7 Runtime error 0 ms 9536 KB gettid (syscall #186) was called by the program (disallowed syscall)
8 Incorrect 0 ms 9536 KB Output isn't correct
9 Halted 0 ms 0 KB
10 Halted 0 ms 0 KB
11 Halted 0 ms 0 KB
12 Halted 0 ms 0 KB
13 Halted 0 ms 0 KB
14 Halted 0 ms 0 KB
15 Halted 0 ms 0 KB
16 Halted 0 ms 0 KB
17 Halted 0 ms 0 KB
18 Halted 0 ms 0 KB
19 Halted 0 ms 0 KB
20 Halted 0 ms 0 KB