Submission #837211

#TimeUsernameProblemLanguageResultExecution timeMemory
837211goddamn06Stove (JOI18_stove)C++14
100 / 100
17 ms1888 KiB
#include<bits/stdc++.h>
#define forin(i,a,b) for(int i = a; i <= b;i++)
#define forde(i,a,b) for(int i = a; i >= b;i--)
#define re(i,a,b) for(int i = a; i < b; i++)
#define forv(a,b) for(auto & a : b)
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define fi first
#define se second
#define pb push_back
#define int long long
#define getbit(x,i) ((x >> i) & 1)
using namespace std;
const int N = 1e5 + 10;
int t[N],res[N-1];
int n,k,ans;
signed main()
{
    cin.tie(0) -> sync_with_stdio(0);
    if(fopen("task.cpp","r"))
    {
        freopen("task.cpp","r",stdin);
        freopen("wa.cpp","w",stdout);
    }
    cin >> n >> k;
    k = n - k;
    forin(i,1,n) cin >> t[i];
    re(i,1,n) res[i] = t[i+1] - t[i] - 1;
    sort(res + 1, res + n);
    ans = n;
    forin(i,1,k)
    {
        ans += res[i];
    }
    cout << ans;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
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("task.cpp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("wa.cpp","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...