Submission #497608

# Submission time Handle Problem Language Result Execution time Memory
497608 2021-12-23T11:00:24 Z penguin133 Stove (JOI18_stove) C++17
100 / 100
28 ms 3028 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Line {
    mutable int k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(int x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
    // for doubles, use inf = 1/.0, div(a,b) = a / b
    static const int inf = 5e18;// implement this
    long double div(int a, int b) { // floored division
        return (long double)((long double)(a)/ (long double)(b)) ;
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) return x->p = inf, 0;
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(int k, int m) { // insert y = kx + m
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
        isect(x, erase(y));
    }
    int query(int x) { // max query
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};

// to use:
// LineContainer hull;
// hull.add(m, c);
// hull.query(x);
// to convert max queries to min queries:
// hull.add(-m, -c);
// -hull.query(x);

int dp[1000005], P[1000005];
priority_queue<int>pq;
int A[1000005];
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n,k;cin >> n >> k;
	for(int i=1;i<=n;i++){
		cin >> A[i];
		if(i > 1)pq.push(A[i] - A[i-1]);
	}
	pq.push(0);
	while(pq.size() > n-k+1)pq.pop();
	int ans = 0;
	while(!pq.empty())ans += pq.top(), pq.pop();
	cout << ans + k;
	
}

Compilation message

stove.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
stove.cpp: In function 'int main()':
stove.cpp:54:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   54 |  while(pq.size() > n-k+1)pq.pop();
      |        ~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 25 ms 3028 KB Output is correct
17 Correct 26 ms 2932 KB Output is correct
18 Correct 24 ms 2936 KB Output is correct
19 Correct 22 ms 2896 KB Output is correct
20 Correct 21 ms 2920 KB Output is correct
21 Correct 23 ms 2980 KB Output is correct
22 Correct 22 ms 2884 KB Output is correct
23 Correct 23 ms 3012 KB Output is correct
24 Correct 28 ms 2896 KB Output is correct