Submission #477976

#TimeUsernameProblemLanguageResultExecution timeMemory
477976mychecksedadHolding (COCI20_holding)C++17
110 / 110
164 ms8140 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() const int N = 1e4+15, M = 110, F = 2147483646, K = 20; int n, l, r, k, arr[M], dp[M][N], temp[M][N]; void solve(){ cin >> n >> l >> r >> k; for(int i = 1; i <= n; ++i) cin >> arr[i]; int sum = 0; for(int i = l; i <= r; ++i) sum += arr[i]; vector<pair<int, int>> a; vector<pair<int, int>> b; for(int i = 1; i <= n; ++i){ if(i < l || i > r) a.pb({arr[i], i}); else b.pb({arr[i], i}); } int ans = sum; for(int j = 0; j <= n; ++j){ for(int l = 0; l <= k; ++l) temp[j][l] = sum; } for(int i = 1; i <= a.size(); ++i){ for(int j = 0; j <= n; ++j){ for(int l = 0; l <= k; ++l){ dp[j][l] = temp[j][l]; } } for(int j = 1; j <= b.size(); ++j){ int dist = abs(a[i - 1].second - b[j - 1].second); for(int l = 0; l <= k; ++l){ dp[j][l] = min({(i > 1 ? temp[j][l] : F), dp[j - 1][l], (l > 0 ? dp[j][l - 1] : F)}); if(l >= dist){ // cout << i << ' ' << j << ' ' << l << ' ' << dp[i][j][l] << ' ' << (a[i - 1].first - b[j - 1].first) << '\n'; dp[j][l] = min(dp[j][l], temp[j - 1][l - dist] + (a[i - 1].first - b[j - 1].first)); } // ans = min(ans, dp[j][l]); } } for(int j = 0; j <= n; ++j){ for(int l = 0; l <= k; ++l){ // cout << i << ' ' << j << ' ' << l << ' ' << dp[j][l] << '\n'; temp[j][l] = dp[j][l]; } } } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); } return 0; }

Compilation message (stderr)

holding.cpp: In function 'void solve()':
holding.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 1; i <= a.size(); ++i){
      |                    ~~^~~~~~~~~~~
holding.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j = 1; j <= b.size(); ++j){
      |                        ~~^~~~~~~~~~~
holding.cpp: In function 'int main()':
holding.cpp:66:16: warning: unused variable 'aa' [-Wunused-variable]
   66 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...