Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <map>
- #include <set>
- #include <unordered_map>
- #include <unordered_set>
- #include <queue>
- #include <deque>
- #include <cmath>
- #include <numeric>
- #include <algorithm>
- #include <ctime>
- #include <chrono>
- #include <random>
- #include <functional>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout << fixed;
- int n, k;
- int ans = 0;
- cin >> n >> k;
- priority_queue <int> st;
- for (int i = 0; i < n; i++) {
- int x;
- cin >> x;
- st.push(x);
- }
- for (int i = 0; i < k; i++) {
- int a = st.top();
- st.pop();
- string s = to_string(a);
- int sm = 0;
- for (auto now : s) {
- sm += int(now) - 48;
- }
- /*int sm = (a % 10) + ((a / 10) % 10) + ((a / 100) % 10) + ((a / 1000) % 10) + ((a / 10000) % 10) + ((a / 100000) % 10) + ((a / 1000000) % 10);*/
- st.push(a - sm);
- ans = sm;
- if (sm == 0) {
- break;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement