답안 #1110046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110046 2024-11-08T14:27:57 Z adkjt Feast (NOI19_feast) C++14
4 / 100
95 ms 4796 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];//quick sum
priority_queue<int,vector<int>,greater<int>> 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 69 ms 1332 KB Output is correct
2 Correct 77 ms 4428 KB Output is correct
3 Correct 77 ms 3808 KB Output is correct
4 Correct 78 ms 3964 KB Output is correct
5 Correct 74 ms 4432 KB Output is correct
6 Correct 78 ms 3076 KB Output is correct
7 Correct 74 ms 3656 KB Output is correct
8 Correct 78 ms 4424 KB Output is correct
9 Correct 74 ms 3656 KB Output is correct
10 Correct 91 ms 3628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 2128 KB Output is correct
2 Correct 42 ms 1620 KB Output is correct
3 Correct 42 ms 2116 KB Output is correct
4 Correct 39 ms 2632 KB Output is correct
5 Incorrect 73 ms 4332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 4796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 1332 KB Output is correct
2 Correct 77 ms 4428 KB Output is correct
3 Correct 77 ms 3808 KB Output is correct
4 Correct 78 ms 3964 KB Output is correct
5 Correct 74 ms 4432 KB Output is correct
6 Correct 78 ms 3076 KB Output is correct
7 Correct 74 ms 3656 KB Output is correct
8 Correct 78 ms 4424 KB Output is correct
9 Correct 74 ms 3656 KB Output is correct
10 Correct 91 ms 3628 KB Output is correct
11 Correct 39 ms 2128 KB Output is correct
12 Correct 42 ms 1620 KB Output is correct
13 Correct 42 ms 2116 KB Output is correct
14 Correct 39 ms 2632 KB Output is correct
15 Incorrect 73 ms 4332 KB Output isn't correct
16 Halted 0 ms 0 KB -