제출 #1328963

#제출 시각아이디문제언어결과실행 시간메모리
1328963adscodingStove (JOI18_stove)C++20
100 / 100
17 ms1736 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __print_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        ++s;
        cerr << "  ,  ";
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = { 0 , ( __print_one(s, args) , 0 )... };
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, X b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template<class X>
bool minimize(X &a, X b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

// --------------------------------------------------------------------------------------------

const int maxn = 1e5 + 3;
int n, K;
ll dp_before[maxn], dp_cur[maxn];

pii S[maxn];

// --------------------------------------------------------------------------------------------





void solve()
{
    cin >> n >> K;
    ll res = n;

    priority_queue<int, vector<int>, greater<int>> pq;
    FOR(i, 1, n)
    {
        cin >> S[i].fi;
        S[i].se = S[i].fi + 1;
    }

    FOR(i, 1, n - 1)
    {
        pq.push(S[i + 1].fi - S[i].se);
    }

    FOR(ik, 1, n - K)
    {
        int x = pq.top(); pq.pop();
        res += x;
    }

    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "TEST"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    solve();
    return 0;
}

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

stove.cpp: In function 'int main()':
stove.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...