답안 #225067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225067 2020-04-19T08:59:00 Z tictaccat Feast (NOI19_feast) C++14
30 / 100
263 ms 12804 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
int N,K;
deque<int> A(500000);
int v[500000], l[500000], r[500000], a[500000];
priority_queue<pair<int,int>> pq;
// priority_queue<pair<int,int>> pq;
 
main() {
 
    cin >> N >> K;

    for (int i = 0; i < N; i++) cin >> A[i];
    while (!A.empty() && A[0] <= 0) A.pop_front();
    while (!A.empty() && A.back() <= 0) A.pop_back();
 
    int cur = 0, t = 0, pos = 0;
    for (int i = 0; i <= N; i++) {
        if (i < N && (cur >= 0) == (A[i] >= 0)) cur += A[i];
        else {
            if (cur == 0) {
                cur = A[i];
                continue;
            }
           // cout << i << " " << cur << " " << t << "\n";
            v[t] = cur;
            l[t] = t-1;
            r[t] = t+1;
            pq.push(make_pair(-abs(cur),t));
            a[t] = 1;
            t++; 
            if (cur > 0) pos++;
            cur = A[i];
        }
    }
 
    int x = 0, ans = 0;
 
    //cout << "\n";
    
    while (!pq.empty()) {
        int val, i;
        tie(val, i) = pq.top();
        pq.pop();
        if (!a[i]) continue;
        if (pos > K) {
            //cout << "a " << v[i] << " " << i << "\n";
            if (v[i] > 0) pos--;
            if (l[i] != -1) {
                if (v[l[i]] > 0) pos--;
                v[i] += v[l[i]];
                r[l[l[i]]] = i;
                a[l[i]] = 0;
                l[i] = l[l[i]];
            }
            if (r[i] != t) {
                if (v[r[i]] > 0) pos--;
                v[i] += v[r[i]];
                l[r[r[i]]] = i;
                a[r[i]] = 0;
                r[i] = r[r[i]];
            }
            pq.push(make_pair(-abs(v[i]),i));
           // cout << "add " << v[i] << " " << i << " " << a[i] << "\n";
            if (v[i] > 0) pos++;
        }
        else {
          //  cout << "b " << v[i] << " " << i << " " << a[i] << "\n";
            if (v[i] > 0) {
                ans += v[i];
              //  cout << "! " << v[i] << "\n";
            }
        }
        //cout << v[i] << " " << i << "\n";
 
        //if (++x == 3) break;
    }
 
    cout << ans << "\n";
 
    //cout <<  pos << "\n";
 
}

Compilation message

feast.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
feast.cpp: In function 'int main()':
feast.cpp:39:9: warning: unused variable 'x' [-Wunused-variable]
     int x = 0, ans = 0;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 4472 KB Output is correct
2 Correct 183 ms 4600 KB Output is correct
3 Correct 185 ms 4480 KB Output is correct
4 Correct 183 ms 4472 KB Output is correct
5 Correct 185 ms 4472 KB Output is correct
6 Correct 184 ms 4472 KB Output is correct
7 Correct 182 ms 4472 KB Output is correct
8 Correct 189 ms 4460 KB Output is correct
9 Correct 183 ms 4460 KB Output is correct
10 Correct 182 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 4472 KB Output is correct
2 Correct 105 ms 4576 KB Output is correct
3 Correct 101 ms 4480 KB Output is correct
4 Correct 100 ms 4472 KB Output is correct
5 Correct 180 ms 4472 KB Output is correct
6 Correct 99 ms 4472 KB Output is correct
7 Correct 104 ms 4472 KB Output is correct
8 Correct 184 ms 4468 KB Output is correct
9 Correct 180 ms 4472 KB Output is correct
10 Correct 103 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 12660 KB Output is correct
2 Correct 245 ms 12660 KB Output is correct
3 Correct 247 ms 12660 KB Output is correct
4 Correct 263 ms 12660 KB Output is correct
5 Correct 244 ms 12660 KB Output is correct
6 Correct 252 ms 12532 KB Output is correct
7 Correct 250 ms 12660 KB Output is correct
8 Correct 245 ms 12660 KB Output is correct
9 Correct 250 ms 12804 KB Output is correct
10 Correct 246 ms 12664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4480 KB Output is correct
2 Correct 8 ms 4480 KB Output is correct
3 Correct 10 ms 4480 KB Output is correct
4 Incorrect 7 ms 4480 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4480 KB Output is correct
2 Correct 8 ms 4480 KB Output is correct
3 Correct 10 ms 4480 KB Output is correct
4 Incorrect 7 ms 4480 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4480 KB Output is correct
2 Correct 8 ms 4480 KB Output is correct
3 Correct 10 ms 4480 KB Output is correct
4 Incorrect 7 ms 4480 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 4472 KB Output is correct
2 Correct 183 ms 4600 KB Output is correct
3 Correct 185 ms 4480 KB Output is correct
4 Correct 183 ms 4472 KB Output is correct
5 Correct 185 ms 4472 KB Output is correct
6 Correct 184 ms 4472 KB Output is correct
7 Correct 182 ms 4472 KB Output is correct
8 Correct 189 ms 4460 KB Output is correct
9 Correct 183 ms 4460 KB Output is correct
10 Correct 182 ms 4472 KB Output is correct
11 Correct 99 ms 4472 KB Output is correct
12 Correct 105 ms 4576 KB Output is correct
13 Correct 101 ms 4480 KB Output is correct
14 Correct 100 ms 4472 KB Output is correct
15 Correct 180 ms 4472 KB Output is correct
16 Correct 99 ms 4472 KB Output is correct
17 Correct 104 ms 4472 KB Output is correct
18 Correct 184 ms 4468 KB Output is correct
19 Correct 180 ms 4472 KB Output is correct
20 Correct 103 ms 4472 KB Output is correct
21 Correct 251 ms 12660 KB Output is correct
22 Correct 245 ms 12660 KB Output is correct
23 Correct 247 ms 12660 KB Output is correct
24 Correct 263 ms 12660 KB Output is correct
25 Correct 244 ms 12660 KB Output is correct
26 Correct 252 ms 12532 KB Output is correct
27 Correct 250 ms 12660 KB Output is correct
28 Correct 245 ms 12660 KB Output is correct
29 Correct 250 ms 12804 KB Output is correct
30 Correct 246 ms 12664 KB Output is correct
31 Correct 8 ms 4480 KB Output is correct
32 Correct 8 ms 4480 KB Output is correct
33 Correct 10 ms 4480 KB Output is correct
34 Incorrect 7 ms 4480 KB Output isn't correct
35 Halted 0 ms 0 KB -