RT,本人代码开 C++14 就 TLE,开 C++20 就 AC,最慢的点 3.6s,这是为啥呀。
代码:
#define orz GCC
#pragma orz optimize("Ofast,-falign-functions,-falign-jumps,-falign-labels,-falign-loops,-fcaller-saves,-fcrossjumping,-fcse-follow-jumps,-fdelete-null-pointer-checks,-fdevirtualize,-fexpensive-optimizations,-ffast-math,-fgcse,-fgcse-lm,-fhoist-adjacent-loads,-findirect-inlining,-finline,-fipa-sra,-fno-stack-protector,-foptimize-sibling-calls,-fpartial-inlining,-fpeephole2,-freorder-blocks,-freorder-functions,-frerun-cse-after-loop,-fsched-interblock,-fsched-spec,-fschedule-insns,-fschedule-insns2,-fstrict-aliasing,-fthread-jumps,-ftree-pre,-ftree-switch-conversion,-ftree-tail-merge,-ftree-vrp,-funroll-loops")
#pragma orz target("abm,avx,mmx,popcnt,sse,sse2,sse3,sse4,ssse3,tune=native")
#include<bits/stdc++.h>
using namespace std;
// #define DEBUG 1 // 调试开关
struct IO{//by Tx_Lcy
#define MAXSIZE (1<<20)
#define isdigit(x) (x>='0'&&x<='9')
char buf[MAXSIZE],*p1,*p2;
char pbuf[MAXSIZE],*pp;
#if DEBUG
#else
IO():p1(buf),p2(buf),pp(pbuf){}
~IO(){fwrite(pbuf,1,pp-pbuf,stdout);}
#endif
inline char gc(){
#if DEBUG
return getchar();
#endif
if (p1==p2) p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin);
return p1==p2?' ':*p1++;
}
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
template <class T>
inline void read(T &x){
double tmp=1;bool sign=0;
x=0;char ch=gc();
for (;!isdigit(ch);ch=gc()) if (ch=='-') sign=1;
for (; isdigit(ch);ch=gc()) x=x*10+(ch-'0');
if (ch=='.')
for (ch=gc();isdigit(ch);ch=gc()) tmp/=10.0,x+=tmp*(ch-'0');
if (sign) x=-x;
}
inline void read(char *s){
char ch = gc();
for (;blank(ch);ch=gc());
for (;!blank(ch);ch=gc()) *s++=ch;
*s=0;
}
inline void read(char &c){for (c=gc();blank(c);c=gc());}
inline void push(const char &c) {
#if DEBUG
putchar(c);
#else
if (pp-pbuf==MAXSIZE) fwrite(pbuf,1,MAXSIZE,stdout),pp=pbuf;
*pp++=c;
#endif
}
template <class T>
inline void write(T x){
if (x<0) x=-x,push('-');
static T sta[35];T top=0;
do{sta[top++]=x%10,x/=10;}while (x);
while (top) push(sta[--top]+'0');
}
template <class T>
inline void write(T x,char lastChar){write(x),push(lastChar);}
template <class T>
inline void writeln(T x){write(x);push('\n');}
}io;
int const N=1e5+10;
long long f[N];
signed main(){
int n;io.read(n);
for (register int i=1;i<=n;++i) f[i]=-1e18;
for (register int i=1;i<=n;++i){
long long x;io.read(x);
for (register int j=i;j;--j) f[j]=max(f[j],f[j-1]+j*x);
}
io.write(max(*max_element(f+1,f+n+1),0ll));
return 0;
}