Submission #250534

#TimeUsernameProblemLanguageResultExecution timeMemory
250534Vladikus004Doktor (COCI17_doktor)C++14
50 / 100
748 ms53244 KiB
#include <bits/stdc++.h> #define inf 2e9 #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; const int N = 500000 + 3; int n, a[N], b[N], sum[N]; map <int, int> cnt, last; pii mx = {-inf, -inf}; int get_sum(int l, int r){ if (!l) return sum[r]; return sum[r] - sum[l - 1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LOCAL cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++){ b[i] = a[i] + i; cnt[b[i]]++; last[b[i]] = i; if (a[i] == i + 1) sum[i] = 1; if (i) sum[i] += sum[i - 1]; } for (auto u: cnt){ mx = max(mx,make_pair(u.second - get_sum(a[last[u.first]] - 1, last[u.first]), u.first)); } // cout << mx.first << " " << last[mx.second] << "\n"; // for (auto u: cnt) cout << u.first << " : " << u.second << "\n"; // cout << mx.first << " " << mx.second << "!!!\n"; // int l = n, r = -1; // for (int i = 0; i < n; i++){ // if (b[i] == mx.second){ // l = a[i] - 1; // r = i; // } // } // cout << a[l]<< " " << a[r]; cout << a[a[last[mx.second]] - 1] << " " << a[last[mx.second]] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...