답안 #1113203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113203 2024-11-16T03:46:24 Z HiepVu217 Feast (NOI19_feast) C++17
0 / 100
114 ms 7328 KB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
const int N = 3e5 + 17;
int n, k;
long long a[N];
pair <long long, int> f[N], m;
inline pair <long long, int> calc (int c)
{
    f[0] = m = {0, 0};
    for (int i = 1; i <= n; ++i)
    {
        f[i] = f[i - 1];
        if (m.first + a[i] - c > f[i].first || (m.first + a[i] - c == f[i].first && m.second + 1 < f[i].second))
        {
            f[i].first = m.first + a[i] - c;
            f[i].second = m.second + 1;
        }
        if (f[i].first - a[i] > m.first || (f[i].first - a[i] == m.first && f[i].second < m.second))
        {
            m.first = f[i].first - a[i];
            m.second = f[i].second;
        }
    }
    return f[n];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    long long l = 1, r = 3e14;
    while (l < r)
    {
        long long mid = l + r + 1 >> 1LL;
        m = calc (mid);
        if (m.second >= k)
        {
            l = mid;
            continue;
        }
        r = mid - 1;
    }
    m = calc(l);
    long long ans = l * m.second + m.first;
    cout << ans;
}

Compilation message

feast.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
feast.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
feast.cpp: In function 'int main()':
feast.cpp:42:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         long long mid = l + r + 1 >> 1LL;
      |                         ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 7248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 7328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 114 ms 7248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 7248 KB Output isn't correct
2 Halted 0 ms 0 KB -