Advertisement
cyberjab

Попытка E

Nov 9th, 2023
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. #include <set>
  9. #include <unordered_map>
  10. #include <unordered_set>
  11. #include <queue>
  12. #include <deque>
  13. #include <cmath>
  14. #include <numeric>
  15. #include <algorithm>
  16. #include <ctime>
  17. #include <chrono>
  18. #include <random>
  19. #include <functional>
  20.  
  21. using namespace std;
  22.  
  23. int main() {
  24.     ios_base::sync_with_stdio(0);
  25.     cin.tie(0);
  26.     cout << fixed;
  27.     int n, k;
  28.     int ans = 0;
  29.     cin >> n >> k;
  30.     priority_queue <int> st;
  31.     for (int i = 0; i < n; i++) {
  32.         int x;
  33.         cin >> x;
  34.         st.push(x);
  35.     }
  36.     for (int i = 0; i < k; i++) {
  37.         int a = st.top();
  38.         st.pop();
  39.         string s = to_string(a);
  40.         int sm = 0;
  41.         for (auto now : s) {
  42.             sm += int(now) - 48;
  43.         }
  44.         /*int sm = (a % 10) + ((a / 10) % 10) + ((a / 100) % 10) + ((a / 1000) % 10) + ((a / 10000) % 10) + ((a / 100000) % 10) + ((a / 1000000) % 10);*/
  45.         st.push(a - sm);
  46.         ans = sm;
  47.         if (sm == 0) {
  48.             break;
  49.         }
  50.     }
  51.     cout << ans;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement