Submission #1064604

# Submission time Handle Problem Language Result Execution time Memory
1064604 2024-08-18T15:21:59 Z beaconmc Tricks of the Trade (CEOI23_trade) C++14
0 / 100
166 ms 401560 KB
    #include <bits/stdc++.h>
     
    typedef long long ll;
    #define FOR(i,x,y) for(ll i=x; i<y; i++)
    #define FORNEG(i,x,y) for(ll i=x; i>y; i--)
     
    using namespace std;
     
     
    ll dp[250005][205];
     
    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	FOR(i,0,250005)FOR(j,0,205) dp[i][j] = -10000000000000000;
     
    	ll n,k;
    	cin >> n >> k;
    	vector<ll> price(n), sell(n);
    	FOR(i,0,n) cin >> price[i];
    	FOR(i,0,n) cin >> sell[i];
    	FOR(i,0,250005) dp[i][0] = 0;
     
    	FORNEG(i,n-1,-1){
    		FOR(j,0,205){
    			dp[i+1][j] = max(dp[i+1][j], dp[i][j] - price[i]);
    			dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] - price[i] + sell[i]);
    		}
    	}
    	ll ans = -10000000000000000;
     
     
    	FOR(i,k,n+1){
    	
    		ans = max(ans, dp[i][k]);
    	}
    	cout << ans << endl;
     
     
     
     
     
     
     
    }

Compilation message

trade.cpp: In function 'int main()':
trade.cpp:27:21: warning: iteration 204 invokes undefined behavior [-Waggressive-loop-optimizations]
   27 |        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] - price[i] + sell[i]);
      |        ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trade.cpp:4:37: note: within this loop
    4 |     #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   25 |       FOR(j,0,205){
      |           ~~~~~~~                    
trade.cpp:25:7: note: in expansion of macro 'FOR'
   25 |       FOR(j,0,205){
      |       ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 401560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 401420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 401420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 401520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 401520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 401560 KB Output isn't correct
2 Halted 0 ms 0 KB -