Submission #681763

#TimeUsernameProblemLanguageResultExecution timeMemory
681763Cross_RatioAutobahn (COI21_autobahn)C++14
100 / 100
123 ms22088 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int A[100005]; int B[100005]; int C[100005]; signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, K, X; cin >> N >> K >> X; int i, j; for(i=0;i<N;i++) { cin >> A[i] >> B[i] >> C[i]; } vector<array<int, 2>> V; for(i=0;i<N;i++) { V.push_back({A[i], 1}); V.push_back({A[i]+B[i], 2}); V.push_back({C[i]+1, 3}); V.push_back({A[i]+X, 4}); V.push_back({A[i]+B[i]+X, 5}); V.push_back({C[i]+1+X, 6}); } sort(V.begin(),V.end()); int ans = 0, val = 0, pl = 0, mi = 0, cnt1 = 0, cnt2 = 0; int prv = -1; for(auto it : V) { val += (it[0] - prv) * ( (cnt1 >= K ? pl : 0) - (cnt2 >= K ? mi : 0)); if(it[1]==1) cnt1++; if(it[1]==2) pl++; if(it[1]==3) pl--, cnt1--; if(it[1]==4) cnt2++; if(it[1]==5) mi++; if(it[1]==6) mi--, cnt2--; prv = it[0]; ans = max(ans, val); //cout << "Add in " << it[0] << ", type is " << it[1] << '\n'; //cout << val << ' ' << cnt1 << ' ' << pl << ' ' << cnt2 << ' ' << mi << '\n'; } cout << ans; }

Compilation message (stderr)

autobahn.cpp: In function 'int main()':
autobahn.cpp:13:12: warning: unused variable 'j' [-Wunused-variable]
   13 |     int i, j;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...