답안 #687518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687518 2023-01-26T13:21:33 Z speedyArda K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 212 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int MAXN = 1e5+5;
ll pref[MAXN], suf[MAXN], in[MAXN];
int main() 
{
    int n, k;
    cin >> n >> k;
    vector<int> max_idx;
    pref[0] = suf[n+1] = 0;
    for(int i = 1; i <= n; i++) {
        cin >> in[i];
        pref[i] = pref[i - 1] + in[i];
        if(max_idx.size() == 0 || in[max_idx[0]] <=  in[i])
        {
            
            if(!max_idx.empty() && in[max_idx[0]] < in[i])
                max_idx.clear();
            max_idx.push_back(i);
        }
    }
    /*for(int i = n; i >= 1; i--)
    {
        suf[i] = suf[i + 1] + in[i];
    }*/
    ll ans = 1e18;
    for(int idx : max_idx)
    {
        //cout << idx << "\n";
        ll temp = 1e18;
        int right = n;
        ll other = 0;
        while(right > max(idx, n - k + 1))
        {
            other += in[right];
            right--;
        }
        right++;
        for(int left = 0; left <= min(k - 1, idx - 1); left++)
        {
            while(max(0, (n - right)) + left + 1 < k && left <= min(k - 1, idx - 1))
                left++;
            if(max(0, n - right) + left + 1 < k)
                break;
            temp = min(temp, pref[left] + in[idx] + other);
            if(right == n+1)
                break;
            other -= in[right];
            right++;
        }

        ans = min(temp, ans);
    }


    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -