Submission #481430

# Submission time Handle Problem Language Result Execution time Memory
481430 2021-10-20T19:29:38 Z Vovamatrix Stove (JOI18_stove) C++14
100 / 100
24 ms 5452 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define endl "\n"
#define MAXN 100007
ll a[MAXN];
vector<ll> v;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==0) v.pb(a[i]);
        else if(a[i]-a[i-1]>1)
        {
            v.pb(a[i-1]+1);
            v.pb(a[i]);
        }
        if(i==n-1) v.pb(a[i]+1);
    }
    int x=v.size()/2-k;
    ll rez=0;
    //cout<<x<<endl;
    //for(auto q:v) cout<<q<<" ";cout<<endl;
    for(int i=0;i<v.size()-1;i=i+2)
    {
        rez+=v[i+1]-v[i];
    }
    //cout<<rez<<endl;
    if(x<=0) cout<<rez;
    else
    {
        vector<ll> v1;
        for(int i=2;i<v.size()-1;i=i+2)
        {
            v1.pb(v[i]-v[i-1]);
        }
        sort(v1.begin(),v1.end());
        //for(auto q:v1) cout<<q<<" ";
        //cout<<endl;
        for(int i=0;i<x;i++) rez+=v1[i];
        cout<<rez;
    }
    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<v.size()-1;i=i+2)
      |                 ~^~~~~~~~~~~
stove.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i=2;i<v.size()-1;i=i+2)
      |                     ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 18 ms 5352 KB Output is correct
17 Correct 20 ms 5444 KB Output is correct
18 Correct 19 ms 5408 KB Output is correct
19 Correct 18 ms 5352 KB Output is correct
20 Correct 18 ms 5444 KB Output is correct
21 Correct 24 ms 5444 KB Output is correct
22 Correct 19 ms 5444 KB Output is correct
23 Correct 21 ms 5452 KB Output is correct
24 Correct 18 ms 5444 KB Output is correct