제출 #91293

#제출 시각아이디문제언어결과실행 시간메모리
91293HideoK blocks (IZhO14_blocks)C++14
0 / 100
7 ms2040 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 7;
const int INF = 1e9 + 7;

int a[N], us[N], prf[N];
int n, k, mx, s, ans;
int l, r;

main(){
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        mx = max (mx, a[i]);
        us[a[i]]++;
        prf[i] = prf[i - 1] + a[i];
    }
    int k1 = k - 1;
    for (int i = 1; k1 > 0; i++){
        if (a[i] == mx && us[a[i]] == 1)
            break;
        us[a[i]]--;
        k1--;
        l++;
    }
    r = n + 1;
    for (int i = n; k1 > 0; i--){
        if (a[i] == mx && us[a[i]] == 1)
            break;
        us[a[i]]--;
        k1--;
        r--;
    }
    ans = prf[l] + (prf[n] - prf[r - 1]);
    while (l >= 0){
        if (us[mx] > 0) s = prf[l] + (prf[n] - prf[r - 1]);
        us[a[l]]++;
        l--;
        r--;
        us[a[r]]--;
        ans = min(ans, s);
    }
    cout << ans + mx;
}

컴파일 시 표준 에러 (stderr) 메시지

blocks.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...