Submission #1150469

#TimeUsernameProblemLanguageResultExecution timeMemory
1150469nguynStove (JOI18_stove)C++20
50 / 100
1095 ms1224 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define F first
#define S second
#define pb push_back 
#define pii pair<int,int>

const int N = 1e5 + 5;
const int inf = 2e9; 

int n, k; 
int a[N]; 
int f[N]; 

signed main(){
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    if (fopen("INP.INP" ,"r")) {
        freopen("INP.INP" ,"r" , stdin) ;
        freopen("OUT.OUT" , "w" , stdout) ;
    }
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
    	cin >> a[i]; 
    }
    for (int i = 1; i <= n; i++) {
        f[i] = 1;
    }
    for (int i = 2; i <= n; i++) { 
        for (int j = k; j >= 2; j--) {
            f[j] = min(f[j] + a[i] - a[i - 1], f[j - 1] + 1); 
        }
        f[1] += a[i] - a[i - 1]; 
    }
    cout << *min_element(f + 1, f + 1 + k); 
}

Compilation message (stderr)

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