unordered_map sometimes better than map:

got TLE with map on Collecting_Numbers_II.cpp but AC with unordered_map
-unordered is good for a lot of requests and a lot of data
This commit is contained in:
2024-06-04 16:41:13 +02:00
parent 7fd24571df
commit 3bd1aab755
5 changed files with 110 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
// Missing Coin Sum
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n; cin >> n;
vector<ll> coins(n);
for (auto &e: coins) cin >> e;
std::sort(coins.begin(), coins.end());
ll sum = 0;
for (int i{}; i < n; i++) {
if (coins[i] - 1 > sum) {
break;
} else {
sum += coins[i];
}
}
cout << sum + 1 << endl;
return 0;
}