Submission #969005

# Submission time Handle Problem Language Result Execution time Memory
969005 2024-04-24T11:17:45 Z dosts Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 468 KB
//Dost SEFEROĞLU
#pragma GCC optimize("O3,unroll-loops,Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " << 
#define vi vector<int>

const int N = 5e2+1,inf = 2e18,MOD = 1e9+7;


void solve() {
    int n,m;
    cin >> n >> m;
    vi a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    vi dp(n+1,inf);
    dp[0] = 0;
    for (int i=1;i<=n;i++) {
        dp[i] = a[i] <= m ? 1 : -inf;
        for (int j = i-1;j>=1;j--) {
            if (abs(a[i]-a[j]) <= m) dp[i] = max(dp[i],dp[j]+1);
        }
    }
    cout << n-max(0ll,dp[n]) << '\n';
}
                
                            
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Incorrect 0 ms 356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Incorrect 0 ms 356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Incorrect 0 ms 356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Incorrect 0 ms 356 KB Output isn't correct
5 Halted 0 ms 0 KB -