#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
std::cerr << "\033[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
std::cerr << (f++ ? ", " : "") << *L;
std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define get_pos(u,x) int(lower_bound(all(u),x)-begin(u))
using namespace std;
using ll = int_fast64_t;
using ld = long double;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
const int inf = 1e9;
const int mod = 1000000007;
const ll INF = 1e18;
const int maxn = 5002;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
vector<tuple<int,int,int>> seg;
for (int i = 0; i < m; i++) {
int l, r, c;
cin >> l >> r >> c;
if (l > r) swap(l, r);
--l, --r;
seg.pb(l, r, c);
}
vector<ll> pref(n);
for (auto [l, r, c]: seg)
pref[l] += c, pref[r] -= c;
for (int i = 1; i < n; i++) pref[i] += pref[i-1];
sort(all(seg));
auto calc = [&](ll x) {
vector<ll> need(n);
for (int i = 0; i < n; i++)
need[i] = max<ll>(0, (pref[i] - x + 1) / 2);
int cnt = 0;
ll sum = 0;
max_heap<pair<int,int>> pq;
min_heap<pair<int,int>> cover;
for (int i = 0, it = 0; i < n; i++) {
while (it < seg.size() && get<0>(seg[it]) <= i) {
auto [l, r, c] = seg[it];
pq.emplace(r, c);
it++;
}
while (cover.size() && cover.top().first <= i) {
sum -= cover.top().second;
cover.pop();
}
while (sum < need[i]) {
assert (!pq.empty());
auto [r, c] = pq.top(); pq.pop();
assert (r > i);
cover.emplace(r, c);
sum += c;
}
}
return x + cnt;
};
ll p0 = 0;
ll p1 = 1;
for (ll s = 1LL << 50; s > 1; s >>= 1) {
if (calc(p0 + s - 2) > calc(p0 + s))
p0 += s;
if (calc(p1 + s - 2) > calc(p1 + s))
p1 += s;
}
cout << min(calc(p0), calc(p1)) << '\n';
}
Compilation message
arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:50:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
50 | for (auto [l, r, c]: seg)
| ^
arranging_tickets.cpp: In lambda function:
arranging_tickets.cpp:66:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | auto [l, r, c] = seg[it];
| ^
arranging_tickets.cpp:76:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
76 | auto [r, c] = pq.top(); pq.pop();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |