Submission #569800

#TimeUsernameProblemLanguageResultExecution timeMemory
569800AmirElarbiAutobahn (COI21_autobahn)C++14
50 / 100
1071 ms136164 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 1e9 #define eps 1e-7 #define eps1 1e-2 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 2e5+5 using namespace std; const int MOD = 1e4+7; const int nax = 2e6+7; typedef complex<int> Point; #define X real() #define Y imag() int n,x,ka; ll tot[nax], s[nax], e[nax], t[nax], cnt[nax],pref[nax], rev[nax]; set<ll> ind; map<ll,ll> cnv; void add(ll pos){ ind.insert(pos); ind.insert(pos + x); ind.insert(pos - x); } int main() { optimise; cin >> n >> ka >> x; ll res = 0; for (int i = 0; i < n; ++i) { cin >> s[i] >> t[i] >> e[i]; add(s[i]); add(e[i]+1); add(e[i]); add(s[i]+t[i]); } int k = 0, mxd; for(auto y : ind){ cnv[y] = k; rev[k] = y; mxd = y; k++; } for (int i = 0; i < n; ++i) { cnt[cnv[s[i]] +1]++; cnt[cnv[e[i] + 1] +1]--; tot[cnv[s[i] + t[i]] +1]++; tot[cnv[e[i] + 1] +1]--; } for (int i = 1; i < k; ++i) { cnt[i] += cnt[i-1]; tot[i] += tot[i-1]; } for (int i = 1; i < k; ++i) { pref[i] = pref[i-1]; if(cnt[i-1] >= ka && i-2 >=0) pref[i] += (rev[i-1]-rev[i-2])*tot[i-1]; } for (int i = 0; i < k; ++i) { int to = cnv[rev[i]+x]+1; if(rev[i]+x > mxd) break; res = max(res, pref[to] - pref[i+1]); } cout << res << endl; }

Compilation message (stderr)

autobahn.cpp: In function 'int main()':
autobahn.cpp:77:23: warning: 'mxd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |         if(rev[i]+x > mxd) break;
      |                       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...