답안 #1110047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110047 2024-11-08T14:29:08 Z adkjt Feast (NOI19_feast) C++14
12 / 100
95 ms 4664 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int,int>
#define ll long long

int a[311111];
priority_queue<ll,vector<ll>,greater<ll>> pq;

int main()
{
    int n,k;
    cin>>n>>k;
    ll ans=0,cnt=0,cur=0;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        if(a[i]>=0&&a[i-1]>=0) {
            cur+=a[i];
        }
        else if(a[i]<0&&a[i-1]<0)
        {
            cur-=a[i];
        }
        else if(a[i]>=0&&a[i-1]<0){
            pq.push(cur);

            cur=a[i];

        }
        else if(a[i]<0&&a[i-1]>=0)
        {
            pq.push(cur);
            ans+=cur;
            cnt++;
            cur=-a[i];
        }
        //cout<<ans<<'\n';
    }
    if(a[n]>=0) pq.push(cur),cnt++,ans+=cur;
    //cout<<'\n';
    while(cnt>k)
    {
        //cout<<ans<<'\n';
        int now=pq.top();
        ans-=now;
        cnt--;
        pq.pop();
    }
    cout<<max(ans,(ll)0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1352 KB Output is correct
2 Correct 75 ms 1384 KB Output is correct
3 Correct 95 ms 1352 KB Output is correct
4 Correct 74 ms 1588 KB Output is correct
5 Correct 72 ms 1344 KB Output is correct
6 Correct 70 ms 1520 KB Output is correct
7 Correct 78 ms 1476 KB Output is correct
8 Correct 79 ms 1432 KB Output is correct
9 Correct 78 ms 1352 KB Output is correct
10 Correct 71 ms 1352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 1352 KB Output is correct
2 Correct 36 ms 1356 KB Output is correct
3 Correct 36 ms 1352 KB Output is correct
4 Correct 36 ms 1352 KB Output is correct
5 Correct 68 ms 1484 KB Output is correct
6 Correct 37 ms 2264 KB Output is correct
7 Correct 48 ms 2340 KB Output is correct
8 Correct 78 ms 3400 KB Output is correct
9 Correct 77 ms 2888 KB Output is correct
10 Correct 37 ms 2632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 4664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1352 KB Output is correct
2 Correct 75 ms 1384 KB Output is correct
3 Correct 95 ms 1352 KB Output is correct
4 Correct 74 ms 1588 KB Output is correct
5 Correct 72 ms 1344 KB Output is correct
6 Correct 70 ms 1520 KB Output is correct
7 Correct 78 ms 1476 KB Output is correct
8 Correct 79 ms 1432 KB Output is correct
9 Correct 78 ms 1352 KB Output is correct
10 Correct 71 ms 1352 KB Output is correct
11 Correct 34 ms 1352 KB Output is correct
12 Correct 36 ms 1356 KB Output is correct
13 Correct 36 ms 1352 KB Output is correct
14 Correct 36 ms 1352 KB Output is correct
15 Correct 68 ms 1484 KB Output is correct
16 Correct 37 ms 2264 KB Output is correct
17 Correct 48 ms 2340 KB Output is correct
18 Correct 78 ms 3400 KB Output is correct
19 Correct 77 ms 2888 KB Output is correct
20 Correct 37 ms 2632 KB Output is correct
21 Incorrect 87 ms 4664 KB Output isn't correct
22 Halted 0 ms 0 KB -