Submission #860219

# Submission time Handle Problem Language Result Execution time Memory
860219 2023-10-12T08:41:27 Z StefanSebez Stove (JOI18_stove) C++14
100 / 100
70 ms 6552 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main()
{
    int n,k;cin>>n>>k;
    int a[n+1];
    set<pair<int,int> >st;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int res=0;
	for(int i=1;i<n;i++)
	{
		st.insert({a[i+1]-a[i],i});
	}
	/*auto i=st.begin();
	while(i!=st.end())
	{
		pair<int,int> x=*i;
		cout<<x.fi<<" "<<x.se<<endl;
		i=next(i);
	}*/
	//res=a[n]-a[1]+1;
	bool was[n+1]={0};
	int ct=1;
	while(ct<k && !st.empty())
	{
		pair<int,int>x=*st.rbegin();
		//res-=x.fi;
		ct++;
		was[x.se]=true;
		st.erase(x);
		//cout<<res<<endl;
	}
	for(int i=1;i<n;i++)
	{
		if(!was[i])res+=a[i+1]-a[i];
	}
	res+=ct;
	cout<<res<<endl;
    return 0;
}
# 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 344 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 436 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 600 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 344 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 436 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 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 448 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 604 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 344 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 436 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 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 448 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 53 ms 6400 KB Output is correct
17 Correct 51 ms 6484 KB Output is correct
18 Correct 53 ms 6376 KB Output is correct
19 Correct 55 ms 6544 KB Output is correct
20 Correct 55 ms 6408 KB Output is correct
21 Correct 57 ms 6484 KB Output is correct
22 Correct 56 ms 6424 KB Output is correct
23 Correct 70 ms 6552 KB Output is correct
24 Correct 56 ms 6484 KB Output is correct