Submission #223544

# Submission time Handle Problem Language Result Execution time Memory
223544 2020-04-15T11:08:49 Z Ruxandra985 Stove (JOI18_stove) C++14
0 / 100
4 ms 256 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 , mini = v[1] , cmin = 0;

    for (i = 1 ; i <= n ; i++){
        dp[i] = 0;
        dp[i] = cost + mini + v[i] + 1;
        cnt[i] = cmin + 1;

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

        if (dp[i] - v[i + 1] < mini){
            mini = dp[i] - v[i + 1];
            cmin = 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;
    }
    st--;
    solve(st , n);

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

    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:36: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:38: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 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -