Dang_Quan_10_Tin

DAYCON TS10 PTNK 2012-2013

Jan 15th, 2022
680
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define task "DAYCON"
  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. constexpr ll Inf = 1e17;
  13.  
  14. int n, k;
  15. ll a[N], b[N];
  16.  
  17. void Read()
  18. {
  19.     cin >> n >> k;
  20.  
  21.     for (int i = 1; i <= n; ++i)
  22.     {
  23.         cin >> a[i];
  24.         b[i] = b[i - 1] + a[i];
  25.     }
  26. }
  27.  
  28. void Solve()
  29. {
  30.     ll ans(-Inf);
  31.  
  32.     for (int i = k; i <= n; ++i)
  33.         ans = max(ans, b[i] - b[i - k]);
  34.  
  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.  
RAW Paste Data