Submission #994848

# Submission time Handle Problem Language Result Execution time Memory
994848 2024-06-08T07:32:19 Z StuckOnA Stove (JOI18_stove) C++17
100 / 100
16 ms 3008 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define pf(x, y) (x).insert((x).begin(), y) 
#define int long long
#define nosync() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define db(x) cerr << #x << " = " << x << endl;
#define duck cerr << "Duck" << endl;
#define __ << ' ' <<
#define endl '\n'
#define tcT template<class T
#define mp make_pair
#define f first
#define s second
#define cyn(x) cout << (x ? "YES" : "NO") << endl;
//#define remove_debug

using str = string;
using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<str>;
using vpi = vector<pi>;
using si = set<int>;
using mi = map<int, int>;
using mc = map<char, int>;
using ms = map<str, int>;

tcT > void input (vector<T> &x)
{
	for (auto &i : x) cin >> i;
}

tcT > void print (T x)
{
	for (auto i : x) cout << i << ' ';
	cout << endl;
}

tcT > void printfs (T x)
{
	for (auto i : x) cout << i.f __ i.s << endl;
}

tcT > void empty (T x) {}

#ifdef remove_debug
	#define cerr if(false) cerr
	#define print(x) empty(x)
	#define printfs(x) empty(x)
#endif

void init()
{
	fclose(fopen("output.txt", "w"));
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "a", stdout);
	freopen("output.txt", "a", stderr);
}

void usaco(char *S)
{
	char I[99],O[99];
	sprintf(I,"%s.in",S);
	sprintf(O,"%s.out",S);
	freopen(I,"r",stdin);
	freopen(O,"w",stdout);
}

void solve() {
	int n, k;
	cin >> n >> k;
	vi v(n), vd(n - 1);
	input(v);
	for (int i = 0; i < n - 1; i++)
		vd[i] = v[i + 1] - v[i] - 1;
	sort(rall(vd));
	int sum = 0;
	for (int i = 0; i < k - 1; i++)
		sum += vd[i];
	cout << v[n - 1] - v[0] - sum + 1 << endl;
}

signed main() 
{
	nosync();
	
	#ifdef local
		init();
	#else
		//usaco("task_name");
	#endif	
	
	int t = 1;
	//cin >> t;
	for (int c = 1; c <= t; c++) {
		//cerr << "Case" << c << ": ";
		solve(); 
	}

	return 0;
}

Compilation message

stove.cpp: In function 'void init()':
stove.cpp:58:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:59:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  freopen("output.txt", "a", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:60:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  freopen("output.txt", "a", stderr);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp: In function 'void usaco(char*)':
stove.cpp:68:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  freopen(I,"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~
stove.cpp:69:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  freopen(O,"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 16 ms 2908 KB Output is correct
17 Correct 14 ms 2916 KB Output is correct
18 Correct 14 ms 3000 KB Output is correct
19 Correct 13 ms 3008 KB Output is correct
20 Correct 14 ms 2908 KB Output is correct
21 Correct 15 ms 2908 KB Output is correct
22 Correct 14 ms 2908 KB Output is correct
23 Correct 14 ms 2908 KB Output is correct
24 Correct 14 ms 3004 KB Output is correct