# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
738966 |
2023-05-09T17:47:37 Z |
ThylOne |
Stove (JOI18_stove) |
C++14 |
|
62 ms |
2384 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct inter{
int start;
int end;
};
const int MAX_SIZE = (1<<18)+1;
const int LEAF = 1<<17;
pair<int,int> BT[MAX_SIZE];
pair<int,int> maxiPAIR(pair<int,int>a,pair<int,int>b){
if(a.first>b.first){
return a;
}else{
return b;
}
}
void fillBT(vector<int> &a){
for(int i = 0 ; i<MAX_SIZE;i++){
BT[i] = {-1,-1};
}
for(int i = 0 ; i < a.size();i++){
BT[i+LEAF] = {a[i],i};
}
for(int i = LEAF-1;i>=1;i--){
BT[i] = maxiPAIR(BT[2*i],BT[2*i+1]);
}
}
pair<int,int> requestMAX(int a,int b){
if(a==b)return BT[a];
if(a>b)return {-1,-1};
if(a&1){
return maxiPAIR(BT[a],requestMAX(a+1,b));
}else if(!(b&1)){
return maxiPAIR(BT[b],requestMAX(a,b-1));
}else{
return requestMAX(a/2,b/2);
}
}
pair<int,int> maxiBT(int a,int b){
return requestMAX(a+LEAF,b+LEAF);
}
bool operator<(inter const a,inter const b){
return maxiBT(a.start,a.end-1).first>maxiBT(b.start,b.end-1).first;
}
int main(){
int n,k;cin>>n>>k;
vector<int> t(n);
for(int i = 0 ; i < n ; i ++){
cin>>t[i];
}
sort(t.begin(),t.end());
vector<pair<int,int>> delay;
for(int i = 0 ; i < n-1;i++){
delay.push_back({t[i+1]-t[i],i});
}
sort(delay.rbegin(),delay.rend());
vector<int> indice;
for(int i=0;i<min(n,k-1);i++){
indice.push_back(delay[i].second);
}
sort(indice.begin(),indice.end());
indice.push_back(n-1);
int mini=-1;
int ind=0;
int score=0;
for(int i = 0 ; i <n;i++){
if(mini==-1){
mini = t[i];
}
if(i==indice[ind]){
ind++;
score+=t[i]-mini+1;
mini=-1;
}
}
cout<<score<<endl;
return 0;
}
Compilation message
stove.cpp: In function 'void fillBT(std::vector<int>&)':
stove.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0 ; i < a.size();i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
49 ms |
1848 KB |
Output is correct |
17 |
Correct |
50 ms |
1840 KB |
Output is correct |
18 |
Correct |
53 ms |
1740 KB |
Output is correct |
19 |
Correct |
51 ms |
1832 KB |
Output is correct |
20 |
Correct |
54 ms |
1848 KB |
Output is correct |
21 |
Correct |
55 ms |
2228 KB |
Output is correct |
22 |
Correct |
56 ms |
2380 KB |
Output is correct |
23 |
Correct |
56 ms |
2352 KB |
Output is correct |
24 |
Correct |
62 ms |
2384 KB |
Output is correct |