Submission #469816

# Submission time Handle Problem Language Result Execution time Memory
469816 2021-09-01T19:45:42 Z MohamedAliSaidane Sjeckanje (COCI21_sjeckanje) C++14
15 / 110
10 ms 584 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (int)(1e8)
#define INF (ll) (1e18)
#define all(v) (v).begin(),(v).end()
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);}
ld pointdist(ld x, ld y, ld point) { return ((x-point)*(y-point))/abs(x-y); }
//ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+
////////////******SOLUTION******\\\\\\\\\\\

const int MAX_N = 300;

ll dp[MAX_N];
int n, q;
vll A;

ll f(int i)
{
    if(dp[i] != -1)
        return dp[i];
    ll maxt = A[i];
    ll mint = A[i];
    ll ans = 0;
    for(int j = i; j <n;j  ++)
    {
        maxt = max(maxt,A[j]);
        mint = min(mint,A[j]);
        if(j != n-1)
            ans = max(ans,maxt-mint+f(j+1));
        else
            ans = max(ans,maxt-mint);
    }
    return dp[i] = ans;
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> q;
    A.assign(n,0);
    for(int i = 0; i <n; i ++) cin >> A[i];
    while(q--)
    {
        int l,  r;
        ll val;
        cin >> l>> r >> val;
        for(int u = l-1; u < r; u ++)
            A[u] += val;
        memset(dp,-1,sizeof(dp));
        cout << f(0) << '\n';
    }
}
/*
Identify problem diagram: Brute force, Greedy, Dynamic Programming, Divide and Conquer
Reformulate the problem into something more theoretical
!!!!! IMPLICIT GRAPH ??????
!!!!! PAY ATTENTION TO THE CONSTRAINTS: DP nD ? BF ? BITMASKING ?
!!!!! SOLVE THE SUBTASKS FIRST: IT'S TOTALLY OK NOT TO SOLVE THE PROBLEM ENTIRELY
Search for multiple approaches: select the seemingly optimal one
Remember that you're the king of CP
Change your approach
Imagine Corner cases before submitting
Don't spend too much time on the problem: move on !
*/

Compilation message

Main.cpp:26:1: warning: multi-line comment [-Wcomment]
   26 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 332 KB Output is correct
2 Correct 10 ms 328 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 328 KB Output is correct
5 Correct 10 ms 336 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 332 KB Output is correct
2 Correct 10 ms 328 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 328 KB Output is correct
5 Correct 10 ms 336 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Runtime error 1 ms 584 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 332 KB Output is correct
2 Correct 10 ms 328 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 328 KB Output is correct
5 Correct 10 ms 336 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Runtime error 1 ms 584 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -