답안 #879640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879640 2023-11-27T19:09:42 Z amin_2008 Stove (JOI18_stove) C++17
100 / 100
20 ms 3736 KB
#pragma GCC optimize ("O3")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// author: amin_2008

#define ios          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll           long long
#define vi           vector<int>
#define vs           vector<string>
#define vc           vector<char>
#define vl           vector<ll>
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define pb           push_back
#define bpc          __builtin_popcount
#define pii          pair<int, int>
#define pll          pair<ll, ll>
#define piii         pair<pii, int>
#define vpii         vector<pii>
#define vpll         vector<pll>
#define vvpii        vector<vpii>
#define vvi          vector<vector<int>>
#define vvl          vector<vector<ll>>
#define ins          insert
#define ts           to_string
#define F            first
#define S            second
#define lb           lower_bound
#define ub           upper_bound
#define ld           long double
#define ull          unsigned long long
#define endl         '\n'
#define int          ll

using namespace std;
using namespace __gnu_pbds;
using namespace __cxx11;
template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const int mod = 1e9+7;
const int sz = 2e5+5;
const int N = 100005;
const int logg = 18;
const int P = 40000005;
const int M = 5e5+5;

int a[sz];

void solve()
{
    int n, k;
    cin >> n >> k;
    vi v(n);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 2; i <= n; i++)
        if ( a[i] - a[i-1] - 1 ) 
            v.pb(a[i] - a[i-1] - 1);
    if ( k >= (int)v.size() + 1 ) 
    {
        cout << n << endl;
        return;
    }
    sort(all(v));
    int res = n;
    for(int i = 0; i < v.size() - k + 1; i++)
        res += v[i];
    cout << res << endl;
}

signed main()
{
    ios;
    //precompute();
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:72:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   72 |     for(int i = 0; i < v.size() - k + 1; i++)
      |                    ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 1 ms 468 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 1 ms 468 KB Output is correct
9 Correct 1 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 480 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 1 ms 468 KB Output is correct
9 Correct 1 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 480 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 15 ms 3672 KB Output is correct
17 Correct 15 ms 3736 KB Output is correct
18 Correct 16 ms 3552 KB Output is correct
19 Correct 15 ms 3676 KB Output is correct
20 Correct 16 ms 3676 KB Output is correct
21 Correct 20 ms 3672 KB Output is correct
22 Correct 16 ms 3672 KB Output is correct
23 Correct 18 ms 3672 KB Output is correct
24 Correct 16 ms 3676 KB Output is correct