Getting Wrong answer using maps on same logic and getting accepted solution using vectors in C++

Revision en3, by aditraj2004, 2023-09-17 02:48:19

I was solving the problem https://codeforces.com/contest/1814/problem/C using C++ maps was getting wrong answer on Codeforces submission , was getting the correct answer by compiling and running the same code on the sublime text. I tried Custom Invocation , still was getting wrong answer . I solved the same problem with the same logic using vectors of pair and pair and got accepted solution . I am unable to understand why the solution using maps failed. Problem Link :- https://codeforces.com/contest/1814/problem/C` Submitted Solution using Maps in C++ :- https://codeforces.com/contest/1814/submission/223668739 Accepted Solution using vector : https://codeforces.com/contest/1814/submission/223672537 Code of Map Solution :-

include<bits/stdc++.h>

void solve() { int n = 0 , s1 = 0 , s2 = 0; cin >> n >> s1 >> s2; vector v(n); vector ans[2]; map <int, vector > freq; for (int i = 0; i < n; i++) { cin >> v[i]; freq[v[i]].push_back(i + 1); } auto it = --(freq.end()); while (it != --(freq.begin())) { for (auto &m : it->ss) { if ((sz(ans[0]) + 1) * s1 >= (sz(ans[1]) + 1) * s2) { ans[1].push_back(m); } else { ans[0].push_back(m); } } it--; } for (int i = 0; i < 2; i++) { cout << sz(ans[i]) << " "; for (auto &k : ans[i]) { cout << k << " "; } cout << nline; } }

I thought the issue is happening when the map has only one element , so i tried to cover the case when the map has only one element separately , but still got the same error. The code is failing on this test case :-

n = 5 , s1 = 1 , s2 = 1 value of the array :- 1 1 1 1 1

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English aditraj2004 2023-09-17 02:50:18 979
en3 English aditraj2004 2023-09-17 02:48:19 0 (published)
en2 English aditraj2004 2023-09-17 02:47:46 45 (saved to drafts)
en1 English aditraj2004 2023-09-17 02:44:23 1953 Initial revision (published)