# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
754619 |
2023-06-08T07:06:43 Z |
Rafat |
Stove (JOI18_stove) |
C++17 |
|
19 ms |
2272 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<bool> vb;
ll mod = 1e9 + 7;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(ll i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
using namespace std;
//ll ans;
/*void bfs(vvp64 adj, ll source, ll n, ll choice, vb used, v64 val)
{
queue<p64>q;
// v64 d(n, LLONG_MAX);
q.push(mp(source, LLONG_MAX));
//vb used(n, false);
//d[source] = 0;
used[source] = true;
while(!q.empty())
{
p64 v = q.front();
q.pop();
for(p64 u : adj[v.fi])
{
if(!used[u.fi]){
if(u.se >= choice){
used[u.fi] = true;
//u.se = min(u.se, v.se);
//val[u.fi] = u.se;
q.push(u);
ans++;
}
}
}
}
//ofstream fout("mootube.out");
//fout << ans << '\n';
//return ans;
}*/
void solve(ll it)
{
ll n, k;
cin >> n >> k;
v64 A(n);
for(ll &x : A) cin >> x;
v64 B;
if(n == 1){
cout << 1;
return;
}
if(k >= n){
cout << n;
return;
}
FOR(1, n - 1, i)
{
B.pb(A[i] - A[i - 1] - 1);
}
sort(rall(B));
ll j = min((ll)B.size(), k - 1), ans = 0;
for(int i = 0; i < B.size(); i++)
{
if(k == 1) break;
ans += B[i];
k--;
}
cout << A[n - 1] - A[0] - ans + 1;
}
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
fast_cin();
ll t = 1;
//cin >> t;
for(int it=1; it<=t; it++)
{
// cout << "Case #" << it+1 << ": ";
solve(it);
}
return 0;
}
Compilation message
stove.cpp: In function 'void solve(ll)':
stove.cpp:96:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i = 0; i < B.size(); i++)
| ~~^~~~~~~~~~
stove.cpp:94:9: warning: unused variable 'j' [-Wunused-variable]
94 | ll j = min((ll)B.size(), k - 1), ans = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
17 ms |
2272 KB |
Output is correct |
17 |
Correct |
17 ms |
2260 KB |
Output is correct |
18 |
Correct |
16 ms |
2260 KB |
Output is correct |
19 |
Correct |
17 ms |
2260 KB |
Output is correct |
20 |
Correct |
18 ms |
2268 KB |
Output is correct |
21 |
Correct |
18 ms |
2272 KB |
Output is correct |
22 |
Correct |
19 ms |
2260 KB |
Output is correct |
23 |
Correct |
16 ms |
2272 KB |
Output is correct |
24 |
Correct |
17 ms |
2260 KB |
Output is correct |