fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int n; // jumlah desa
  9. cout << "Masukkan jumlah desa: ";
  10. cin >> n;
  11.  
  12. if (n > 100000) {
  13. cerr << "Error: Jumlah desa maksimal 100000.\n";
  14. return 1;
  15. }
  16.  
  17. long long totalDDS = 0;
  18. vector<int> dds(n);
  19.  
  20. cout << "Masukkan jumlah DDS untuk setiap desa:\n";
  21. for (int i = 0; i < n; ++i) {
  22. cin >> dds[i];
  23. if (dds[i] < 0) {
  24. cerr << "Error: Jumlah DDS tidak boleh negatif.\n";
  25. return 1;
  26. }
  27. totalDDS += dds[i];
  28. }
  29.  
  30. if (totalDDS > 30000000LL) {
  31. cerr << "Peringatan: Total DDS melebihi 30 juta.\n";
  32. }
  33.  
  34. cout << "\n=== HASIL ===\n";
  35. cout << "Jumlah desa: " << n << "\n";
  36. cout << "Total DDS: " << totalDDS << "\n";
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Masukkan jumlah desa: Masukkan jumlah DDS untuk setiap desa:

=== HASIL ===
Jumlah desa: 5405
Total DDS: 0