Submission #1272260

#TimeUsernameProblemLanguageResultExecution timeMemory
1272260jungle15Stove (JOI18_stove)C++17
100 / 100
14 ms832 KiB
#include <bits/stdc++.h>
using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define Jungle "JOI18_stove"
#define getbit(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1 << (i))
#define cntbit __builtin_popcount
#define MULTEST \
    int nq;     \
    cin >> nq;  \
    while(nq--)

template <typename t> void chkmin(t &a, t b)
{
    if(a > b) a = b;
}

template <typename t> void chkmax(t &a, t b)
{
    if(a < b) a = b;
}

const int mod = 1e9 + 7;

int add(int a, int b)
{
    return (1ll * a + b) % mod;
}

int sub(int a, int b)
{
    return (1ll * a - b + mod) % mod;
}

int mul(int a, int b)
{
    return 1ll * a * b % mod;
}

const int maxn = 1e5;

int n, nk, a[maxn + 2];

void init(void)
{
	cin >> n >> nk;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
}

int res;

void solve(void)
{
    init();
    sort(a + 1, a + n + 1);
    res = a[n] + 1 - a[1];
    for(int i = 1; i < n; i++)
		a[i] = a[i + 1] - a[i] - 1;
	sort(a + 1, a + n);
	for(int i = n - 1; nk > 1; i--, nk--)
		res -= a[i];
	cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);

    if(fopen(Jungle".inp", "r"))
    {
        freopen(Jungle".inp", "r", stdin);
        freopen(Jungle".out", "w", stdout);
    }

//    MULTEST
    solve();

//    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}

Compilation message (stderr)

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