답안 #880185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880185 2023-11-29T02:20:43 Z ReLice Stove (JOI18_stove) C++14
100 / 100
18 ms 4624 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
//#define sz size()
#define bc back()
#define ar array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag=false;
    if(x>y){
        x=y;flag|=true;
    }
    return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag=false;
    if (x<y){
        x=y;flag|=true;
    }
    return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=998244353;
const ll N=2e5+7;
const ld eps=1e-9;

void solve(){
	ll i;
	ll n,m;
	ll a,b;
	cin>>n>>m;
	vector<pair<ll,ll>> v;
	for(i=0;i<n;i++){
		cin>>a;
		v.pb({a,a+1});
	}
	vector<ll> v2;
	sort(all(v));
	for(i=1;i<n;i++){
		v2.pb(v[i].fr-v[i-1].sc);
	}
	sort(all(v2));
	ll sum=n;
	for(i=0;i<n-m;i++)sum+=v2[i];
	cout<<sum<<endl;
}
signed main(){
	start();
    ll t=1;
	//cin>>t;
    while(t--) solve();
    return 0;
}
/*







*/

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:55:7: warning: unused variable 'b' [-Wunused-variable]
   55 |  ll a,b;
      |       ^
stove.cpp: In function 'void fre(std::string)':
stove.cpp:41:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:41:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 632 KB Output is correct
16 Correct 17 ms 4564 KB Output is correct
17 Correct 17 ms 4608 KB Output is correct
18 Correct 18 ms 4564 KB Output is correct
19 Correct 18 ms 4564 KB Output is correct
20 Correct 17 ms 4624 KB Output is correct
21 Correct 17 ms 4396 KB Output is correct
22 Correct 17 ms 4480 KB Output is correct
23 Correct 17 ms 4564 KB Output is correct
24 Correct 17 ms 4564 KB Output is correct