Advertisement
Dang_Quan_10_Tin

SOAM TS10 PTNK 2007-2008

Jan 15th, 2022
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #define task "SOAM"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. using ll = long long;
  9. using ld = long double;
  10.  
  11. constexpr int N = 1e5 + 5;
  12. int n, a[N];
  13.  
  14. void Read()
  15. {
  16.     cin >> n;
  17.  
  18.     for (int i = 1; i <= n; ++i)
  19.         cin >> a[i];
  20. }
  21.  
  22. void Solve()
  23. {
  24.     int ans(-N);
  25.  
  26.     for (int i = 1; i <= n; ++i)
  27.         if (a[i] >= 0)
  28.             ; // Bỏ qua
  29.         else
  30.             ans = max(ans, a[i]);
  31.  
  32.     if (ans == -N) // Không có số âm trong dãy
  33.         cout << 0;
  34.     else
  35.         cout << ans;
  36. }
  37.  
  38. int32_t main()
  39. {
  40.     ios::sync_with_stdio(0);
  41.     cin.tie(0);
  42.     cout.tie(0);
  43.     if (fopen(task ".INP", "r"))
  44.     {
  45.         freopen(task ".INP", "r", stdin);
  46.         freopen(task ".OUT", "w", stdout);
  47.     }
  48.  
  49.     Read();
  50.     Solve();
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement