# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092442 |
2024-09-24T06:17:26 Z |
vjudge1 |
Stove (JOI18_stove) |
C++17 |
|
0 ms |
348 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define stdI freopen("input.txt", "r", stdin);
#define stdO freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define int long long
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,
null_type,less<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;
const int MAXN = 2e5 + 100, INF = 1e18, MOD = 1e9 + 7;
struct bz
{
int w, i, j;
};
void solve()
{
vector<pii> v, vv;
int n, k;
cin >> n >> k;
int a[n];
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a, a + n);
int f = a[0], s = a[0] + 1;
for(int i = 1; i < n; i++)
{
if(a[i] - a[i - 1] <= 2)
{
s = a[i] + 1;
}
else
{
v.push_back(mp(f, s));
f = a[i], s = a[i] + 1;
}
}
v.push_back(mp(f, s));
for(int i = 1; i < v.size(); i++)
{
vv.push_back(mp(v[i].F - v[i - 1].S - 1, i));
}
sort(all(vv));
bool mk[v.size() + 5];
memset(mk, 0, sizeof mk);
int ans = 0; k--;
while((int)vv.size() > 0 && k > 0)
{
pii x = vv.back(); vv.pop_back(); k--;
ans += x.F;
mk[x.S] = 1;
mk[x.S - 1] = 1;
}
int rr = 0;
for(int i = 0; i < v.size(); i++)
{
rr += mk[i];
}
cout << a[n - 1] + 2 - a[0] - rr - ans << "\n";
}
int32_t main()
{
IOS;
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
}
Compilation message
stove.cpp: In function 'void solve()':
stove.cpp:54:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
stove.cpp:70:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |