Submission #223444

# Submission time Handle Problem Language Result Execution time Memory
223444 2020-04-15T09:24:42 Z Ruxandra985 Stove (JOI18_stove) C++14
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;

long long dp[DIMN];
int cnt[DIMN] , v[DIMN];
priority_queue <pair <long long , int> > h;

void solve (long long cost , int n){
    int i;

    while (!h.empty())
        h.pop();

    h.push(make_pair(0,0));

    for (i = 1 ; i <= n ; i++){
        dp[i] = cost - h.top().first + v[i] + 1;
        cnt[i] = h.top().second + 1;

        if (dp[i] > cost + dp[i - 1] + 1){
            dp[i] = cost + dp[i - 1] + 1;
            cnt[i] = 1 + cnt[i - 1];
        }

        h.push(make_pair( -dp[i - 1] + v[i] , cnt[i]));
    }


}
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , k , i;
    long long st , dr , mid;
    fscanf (fin,"%d%d",&n,&k);
    for (i = 1 ; i <= n ; i++)
        fscanf (fin,"%d",&v[i]);

    st = 0;
    dr = 1000000000000000000LL;
    while (st <= dr){
        mid = (st + dr) / 2;
        solve(mid , n);
        if (cnt[n] > k)
            st = mid + 1;
        else
            dr = mid - 1;
    }

    solve(st , n);

    fprintf (fout,"%lld" , dp[n] - 1LL * cnt[n] * st);

    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:37:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&k);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
stove.cpp:39:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -