답안 #687524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687524 2023-01-26T13:31:20 Z speedyArda K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 312 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((n - right + 1) + left + 1 < k && left <= min(k - 1, idx - 1))
                left++;
            if((n - right + 1) + 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 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 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 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -