답안 #331964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331964 2020-11-30T20:18:20 Z Yomapeed Stove (JOI18_stove) C++17
100 / 100
25 ms 3308 KB
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mt make_tuple 
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, k;
        cin >> n >> k;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        if(k == n){
            cout << n;
            return 0;
        }
        vector<ll> diffs;
        for(i = 0; i < n - 1; i++){
            diffs.pb(v[i] - v[i + 1]);
        }
        sort(diffs.begin(), diffs.end());
        ll sz = diffs.size();
        k = k - 1;
        ll ans = 0;
        for(i = 0; i < k; i++){
            ans += diffs[i];
        }
        ans += v[n - 1] - v[0];
        ans += k + 1;
        cout << ans << endl;
    }
    return 0;
}

Compilation message

stove.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("O3")
      | 
stove.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      | 
stove.cpp: In function 'int main()':
stove.cpp:48:12: warning: unused variable 'sz' [-Wunused-variable]
   48 |         ll sz = diffs.size();
      |            ^~
stove.cpp:29:18: warning: unused variable 'j' [-Wunused-variable]
   29 |     ll T = 1, i, j;
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 21 ms 3308 KB Output is correct
17 Correct 22 ms 3308 KB Output is correct
18 Correct 20 ms 3308 KB Output is correct
19 Correct 20 ms 3308 KB Output is correct
20 Correct 21 ms 3308 KB Output is correct
21 Correct 21 ms 3308 KB Output is correct
22 Correct 25 ms 3308 KB Output is correct
23 Correct 24 ms 3308 KB Output is correct
24 Correct 21 ms 3308 KB Output is correct