Submission #152188

# Submission time Handle Problem Language Result Execution time Memory
152188 2019-09-06T18:01:59 Z 12tqian Stove (JOI18_stove) C++14
100 / 100
97 ms 12020 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
const double PI = 4 * atan(1);
 
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
 
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
 
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
 
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}

const int MAX = 1e5 + 5;
vi t;

int main(){
	fast_io();
	int n, k;
	cin >> n >> k;
	f0r(i, n){
		int ti;
		cin >> ti;
		t.eb(ti);
	}
	set<int> tmp;
	for(int x: t) tmp.insert(x);
	t.clear();
	for(int x: tmp) t.eb(x);
	n =  sz(t);
	if(n<= k){
		cout << n << endl;
		return 0;
	}
	int total = t[sz(t) - 1] - t[0] + 1;
	multiset<int> diff;
	f0r(i, n-1){
		diff.insert(t[i+1] - t[i] - 1);
	}
	vi use;
	//cout << t << endl;
	for(int x: diff) use.eb(x);
	reverse(all(use));
	int sum = 0;
	f0r(i, k-1){
		sum += use[i];
	}
	//cout << use << endl;
	//cout << total - sum << endl;
	cout << total  - sum<< endl;
	return 0;
	
}

Compilation message

stove.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
stove.cpp: In function 'void io(std::__cxx11::string)':
stove.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 424 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 424 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 4 ms 632 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 424 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
13 Correct 4 ms 632 KB Output is correct
14 Correct 4 ms 632 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
16 Correct 91 ms 11892 KB Output is correct
17 Correct 92 ms 11824 KB Output is correct
18 Correct 97 ms 11824 KB Output is correct
19 Correct 92 ms 11892 KB Output is correct
20 Correct 93 ms 11892 KB Output is correct
21 Correct 95 ms 11792 KB Output is correct
22 Correct 91 ms 11860 KB Output is correct
23 Correct 91 ms 12020 KB Output is correct
24 Correct 93 ms 12020 KB Output is correct