답안 #1011983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011983 2024-07-01T13:25:25 Z vantam Sjeckanje (COCI21_sjeckanje) C++17
15 / 110
2000 ms 2556 KB
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
const int N=1005 ;
long long i,j,n,q,type,l,r,x,ma,mi,lt,rt;
long long a[200005],dp[200005] ;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #define NAME "test"
    if(fopen(NAME".inp", "r")){
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    cin >> n >> q;
    for(i=1;i<=n;i++) cin >> a[i] ;
    while(q--){
        cin >> l >> r >> x ;
        for(i=l;i<=r;i++) a[i]+=x ;
        dp[0]=0 ;
        for(i=1;i<=n;i++){
             ma=a[i];
             mi=a[i];
             dp[i]=-1e18;
             for(j=i;j>=1;j--){
                  ma=max(ma,a[j]) ;
                  mi=min(mi,a[j]) ;
                  dp[i]=max(dp[i], dp[j-1]+ma-mi) ;
             }
        }
        cout << dp[n] << '\n' ;
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 4 ms 2528 KB Output is correct
4 Correct 5 ms 2556 KB Output is correct
5 Correct 5 ms 2396 KB Output is correct
6 Correct 5 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 4 ms 2528 KB Output is correct
4 Correct 5 ms 2556 KB Output is correct
5 Correct 5 ms 2396 KB Output is correct
6 Correct 5 ms 2512 KB Output is correct
7 Execution timed out 2077 ms 2396 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 4 ms 2528 KB Output is correct
4 Correct 5 ms 2556 KB Output is correct
5 Correct 5 ms 2396 KB Output is correct
6 Correct 5 ms 2512 KB Output is correct
7 Execution timed out 2077 ms 2396 KB Time limit exceeded
8 Halted 0 ms 0 KB -