Submission #154784

#TimeUsernameProblemLanguageResultExecution timeMemory
154784MercenaryStove (JOI18_stove)C++14
100 / 100
26 ms1784 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;

int n , k;

int a[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> k;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i];
    }
    int res = a[n] - a[1] + 1;
    for(int i = n ; i >= 2 ; --i){
        a[i] = a[i] - a[i - 1] - 1;
    }
    sort(a + 2 , a + n + 1 , greater<int>());
//    for(int i = 1 ; i <= n ; ++i)cout << a[i] << endl;
    for(int i = 2 ; i <= k ; ++i)res -= a[i];
    cout << res;
}

Compilation message (stderr)

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