답안 #554451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554451 2022-04-28T12:25:51 Z n0sk1ll Stove (JOI18_stove) C++14
100 / 100
22 ms 2284 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define erase_uni(x) x.erase(unique(all(x)),x.end())
#define inv(n) power((n), mod - 2)
#define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define fff(i,a,b) for (int (i) = (a); (i) <= b; (i)++)
#define bff(i,a,b) for (int (i) = (b)-1; (i) >= (a); (i)--)
#define bfff(i,a,b) for (int (i) = (b); (i) >= (a); (i)--)
#define sum_overflow(a,b) __builtin_add_overflow_p ((a), (b), (__typeof__ ((a) + (b))) 0)
#define mul_overflow(a,b) __builtin_mul_overflow_p ((a), (b), (__typeof__ ((a) + (b))) 0)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;

/*using namespace __gnu_pbds;
template <class T> using oset = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
template <class T> using omset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;*/







//Note to self: Check for overflow

int a[100005];

int main()
{
    FAST;

    int n,k; cin>>n>>k;
    ff(i,0,n) cin>>a[i];
    vector<int> b;
    ff(i,1,n) b.pb(a[i]-a[i-1]-1);
    sort(all(b),greater<int>());

    li ans=n;
    for (int i=n;i>k;i--)
    {
        ans+=b.back();
        b.popb();
    }

    cout<<ans<<"\n";
}

//Note to self: Check for overflow

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
      |                            ^
stove.cpp:54:5: note: in expansion of macro 'ff'
   54 |     ff(i,0,n) cin>>a[i];
      |     ^~
stove.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define ff(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
      |                            ^
stove.cpp:56:5: note: in expansion of macro 'ff'
   56 |     ff(i,1,n) b.pb(a[i]-a[i-1]-1);
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 18 ms 2284 KB Output is correct
17 Correct 22 ms 2264 KB Output is correct
18 Correct 17 ms 2264 KB Output is correct
19 Correct 17 ms 2276 KB Output is correct
20 Correct 19 ms 2252 KB Output is correct
21 Correct 17 ms 2264 KB Output is correct
22 Correct 19 ms 2264 KB Output is correct
23 Correct 18 ms 2280 KB Output is correct
24 Correct 18 ms 2264 KB Output is correct