Submission #295161

#TimeUsernameProblemLanguageResultExecution timeMemory
295161shivensinha4Kralj (COCI16_kralj)C++17
0 / 140
2101 ms39288 KiB
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' int main() { #ifdef shiven freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi adv(n), a(n), b(n), advPref(n); vector<vi> elfHere(n); for_(i, 0, n) { cin >> adv[i]; adv[i] -= 1; advPref[adv[i]] += 1; elfHere[adv[i]].push_back(i); } for_(i, 0, n) cin >> a[i]; for_(i, 0, n) cin >> b[i]; int mn = INT_MAX, mnIdx = -1; for_(i, 0, n) { if (i > 0) adv[i] += adv[i-1]; if (adv[i]-i < mn) { mn = adv[i]-i; mnIdx = i; } } int ans = 0; set<int> s; for_(idx, 0, n) { int i = (mnIdx + i); if (i >= n) i -= n; for (auto j: elfHere[i]) s.insert(b[j]); auto pt = s.lower_bound(a[i]); if (pt == s.end()) { s.erase(s.begin()); } else { ans += 1; s.erase(pt); } } cout << ans << endl; return 0; }

Compilation message (stderr)

kralj.cpp: In function 'int main()':
kralj.cpp:43:7: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |   int i = (mnIdx + i);
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...