-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Expensive_Number.cpp
More file actions
39 lines (32 loc) · 951 Bytes
/
B_Expensive_Number.cpp
File metadata and controls
39 lines (32 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.size();
string best = "";
long long bestNum = 1e18;
long long bestSum = 1;
int bestRemoved = n;
string curr = "";
long long currSum = 0;
for (int i = 0; i < n; ++i) {
curr += s[i];
currSum += s[i] - '0';
if (curr[0] == '0' || currSum == 0) continue;
long long currVal = stoll(curr); // safe up to 18 digits
// Compare: currVal / currSum vs bestNum / bestSum
if (currVal * bestSum < bestNum * currSum) {
bestNum = currVal;
bestSum = currSum;
bestRemoved = n - curr.size();
}
}
cout << bestRemoved << '\n';
}
}