Submission #746984

#TimeUsernameProblemLanguageResultExecution timeMemory
746984nguyentunglamCake 3 (JOI19_cake3)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e5 + 10; pair<int, int> a[N]; int v[N], c[N]; pair<long long, long long> calc(pair<long long, long long> A, pair<long long, long long> B) { if (A.first == B.first) return A.second < B.second ? A : B; return A.first > B.first ? A : B; } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, m; cin >> n >> m; vector<ii> lst; for(int i = 1; i <= n; i++) { int x, y; cin >> x >> y; lst.emplace_back(x, y); } sort(lst.begin(), lst.end(), [] (const ii &x, const ii &y) { return x.se < y.se; }); for(int i = 1; i <= n; i++) tie(v[i], c[i]) = lst[i - 1]; long long l = -1e12, r = 1e12, ans = 0; while (l <= r) { long long tax = l + r >> 1; pair<long long, long long> f, ret; f = ret = make_pair(-1e18, -1e18); for(int i = 1; i <= n; i++) { ret = calc(ret, make_pair(f.first + v[i] - 2 * c[i] - tax, f.second + 1)); pair<long long, long long> g = make_pair(f.first + v[i] - tax, f.second + 1); f = calc(f, g); f = calc(f, make_pair(v[i] - tax + 2 * c[i], 1LL)); } if (ret.second <= m) { ans = ret.first + m * tax; r = tax - 1; } else l = tax + 1; } cout << ans; }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:38:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |         long long tax = l + r >> 1;
      |                         ~~^~~
cake3.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:23:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:24:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...