Submission #1004885

# Submission time Handle Problem Language Result Execution time Memory
1004885 2024-06-21T21:51:47 Z MarwenElarbi Stove (JOI18_stove) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=5e2+5;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n,k;
    cin>>n>>k;
    int tab[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i];
    }
    vector<int> nabba;
    for (int i = 1; i < n; ++i)
    {
        nabba.pb(tab[i]-tab[i-1]-1);
    }
    sort(nabba.begin(),nabba.end());
    int sum=tab[n-1]+1-tab[0];
    for (int i = nabba.size()-1; i >= (int)nabba.size()-k+1  ; --i)
    {
        sum-=nabba[i];
    }
    cout <<sum<<endl;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -