Submission #754575

# Submission time Handle Problem Language Result Execution time Memory
754575 2023-06-08T06:22:57 Z Nika533 Stove (JOI18_stove) C++14
100 / 100
23 ms 5484 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
string s;
void test_case() {
	cin>>n>>k;
	int arr[n];
	for (int i=0; i<n; i++) {
		cin>>arr[i];
	}
	vector<pair<int,int>> v;
	int l=0;
	int r=0;
	for (int i=1; i<n; i++) {
		if (arr[i]==arr[i-1]) {
			r++;
		}
		else {
			v.pb({arr[l],arr[r]});
			l=i;
			r=i;
		}
	}
	v.pb({arr[l],arr[r]});
	m=v.size();
	vector<int> p;
	for (int i=0; i<m; i++) {
		//cout<<v[i].f<<" "<<v[i].s<<endl;
	}
	for (int i=1; i<m; i++) {
		p.pb(v[i].f-v[i-1].s-1);
	}
	sort(all(p));
	int ans=n;
	for (int i=0; i<min(m-1,n-k); i++) {
		ans+=p[i];
	}
	cout<<ans<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1;
	//cin>>T;
	while (T--) {
		test_case();
	}
}

Compilation message

stove.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
stove.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 496 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 496 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 21 ms 5376 KB Output is correct
17 Correct 21 ms 5484 KB Output is correct
18 Correct 23 ms 5432 KB Output is correct
19 Correct 21 ms 5420 KB Output is correct
20 Correct 21 ms 5412 KB Output is correct
21 Correct 20 ms 5444 KB Output is correct
22 Correct 21 ms 5380 KB Output is correct
23 Correct 21 ms 5324 KB Output is correct
24 Correct 21 ms 5432 KB Output is correct