fork download
  1. #include <bits/stdc++.h> // Umum dipakai di competitive programming[web:22][web:24]
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int N;
  9. cin >> N;
  10.  
  11. long long totalPendapatan = 0;
  12. string kode;
  13. long long harga, jumlah;
  14.  
  15. string kodeTerlaris = "";
  16. long long jumlahTerbanyak = -1;
  17.  
  18. for (int i = 0; i < N; i++) {
  19. cin >> kode >> harga >> jumlah;
  20.  
  21. // Hitung pendapatan untuk jenis ini
  22. long long pendapatanJenis = harga * jumlah;
  23. totalPendapatan += pendapatanJenis;
  24.  
  25. // Cek apakah ini layangan terlaris baru
  26. if (jumlah > jumlahTerbanyak) {
  27. jumlahTerbanyak = jumlah;
  28. kodeTerlaris = kode;
  29. } else if (jumlah == jumlahTerbanyak) {
  30. // Jika sama banyak, ambil yang leksikografis lebih kecil
  31. if (kode < kodeTerlaris) {
  32. kodeTerlaris = kode;
  33. }
  34. }
  35. }
  36.  
  37. cout << totalPendapatan << "\n";
  38. cout << kodeTerlaris << "\n";
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5324KB
stdin
A01 5000 10
B02 8000 5
C03 5000 10
D04 4000 12
stdout
0