MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CSES/Sorting/MissingCoinSum.cc:7–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#define int long long
6
7int32_t main(){
8 ios_base::sync_with_stdio(false),cin.tie(nullptr);
9
10 int n; cin >> n;
11 vector<int> V(n); rep(i,0,n) cin>> V[i];
12 sort(V.begin(),V.end());
13 int res = 1;
14 if (V[0] != 1) {
15 cout << 1 << endl;
16 exit(0);
17 }
18 for (int i = 0; i < n && V[i] <= res; ++i) {
19 res += V[i];
20 }
21 cout << res << endl;
22 return 0;
23}
24// 1 2 2 7 9
25// Solution :-
26// we first check if we have a[0] = 1 then we can make sum = 1 else answer = 1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected