Submission #870141

#TimeUsernameProblemLanguageResultExecution timeMemory
870141nghia0912Sjeckanje (COCI21_sjeckanje)C++17
15 / 110
2024 ms484 KiB
#define COPYRIGHT CODE BY TRINH TUAN NGHIA #include<bits/stdc++.h> #define Boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ll long long #define endl "\n" #define st first #define nd second #define ii pair <ll,ll> #define iii pair <ll,ii> #define iiii pair <ii,ii> #define pb push_back #define NAME "recipe" using namespace std; const int N = 2e5 + 10; const int Nsub1 = 210; const int Nsub2 = 3e3 + 10; int n,q ; long long dp[3010]; ll a[N]; void inp (){ cin >> n >> q; for (int i = 1;i <= n; ++i){ cin >> a[i]; } } void reset(){ for (int i =1 ; i <= n; ++i)dp[i] = 0; } void sub1(){ while (q--){ reset(); int l, r, x; cin >> l >> r >> x; for (int i = l; i <= r; ++i){ a[i] += x; } for (int i = 1; i <= n; ++i){ ll minn = a[i]; ll maxx = a[i]; for (int j = i; j >= 1; --j){ minn = min(minn, a[j]); maxx = max(maxx, a[j]); dp[i] = max({dp[i], dp[j - 1] + a[i] - minn, dp[j - 1] + maxx - a[i]}); // if (i == 2 and j == 1)cout << minn << " " << maxx << "\n"; } // cout << dp[i] << " "; } // cout << "\n"; // for (int i =1 ; i <= n; ++i)cout << dp[i] << " "; // cout << "\n"; cout << dp[n] << "\n"; } } void sub2(){ while (q--){ reset(); int l, r, x; cin >> l >> r >> x; for (int i = l; i <= r; ++i){ a[i] += x; } ll minn = 1e18; ll maxx = 0; ll minndp = 1e18; ll maxxdp = -1e18; for (int i = 1; i <= n; ++i){ dp[i] = max({dp[i], a[i] - minndp, maxxdp - a[i]}); minndp = min(minndp, a[i] - dp[i - 1]); maxxdp = max(maxxdp, dp[i - 1] + a[i]); //cout << i << " " << dp[i] << " " << minndp << " " << maxxdp << endl; } cout << dp[n] << endl; } } void solve(){ sub1(); // sub2(); } signed main (){ if (fopen(NAME".inp", "r")){ freopen(NAME".inp", "r", stdin); freopen(NAME".ans", "w", stdout); } Boost; inp(); solve(); } /* input */ /* output */

Compilation message (stderr)

Main.cpp: In function 'void sub2()':
Main.cpp:64:12: warning: unused variable 'minn' [-Wunused-variable]
   64 |         ll minn = 1e18;
      |            ^~~~
Main.cpp:65:12: warning: unused variable 'maxx' [-Wunused-variable]
   65 |         ll maxx = 0;
      |            ^~~~
Main.cpp: In function 'int main()':
Main.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(NAME".ans", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...