fork download
  1. /**
  2. - Solution for: https://m...content-available-to-author-only...j.com/problem/442
  3. - C++ 11/14/17/Themis
  4. **/
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  8. #define mofile(s) freopen(s,"r",stdin)
  9. #define outfile(s) freopen(s,"w",stdout)
  10. #define ll long long
  11. #define ii pair<int,int>
  12. #define iii pair<int,ii>
  13. #define fi first
  14. #define se second
  15. #define tf bool
  16. #define ST stack
  17. #define DQ deque
  18. #define Q queue
  19. #define S string
  20. #define Ma map
  21. #define UM unordered_map
  22. #define SE set
  23. #define str(x) to_string(x)
  24. #define all(a) (a).begin(),(a).end()
  25. #define FOR(i,l,r,d) for(int i=l;i<=r;i+=d)
  26. #define FOD(i,l,r,d) for(int i=r;i>=l;i-=d)
  27. #define xuong cout<<"\n"
  28. #define debug(x) cout<<(x)<<" "
  29. #define ppcnt(x) __builtin_popcountll(x)
  30. #define parity(x) __builtin_parityll(x)
  31. #define lead0(x) __builtin_clzll(x)
  32. #define LOG2 __lg(x)
  33. #define tr0(x) __builtin_ctzll(x)
  34. #define fiset(x) __builtin_ffsll(x)
  35. #define MASK(k) (1LL<<(k))
  36. #define BIT(x,k) ((x)>>(k)&1)
  37. #define pb push_back
  38. #define tron(x) setprecision(x)
  39. #define het return 0
  40. #define base_ 1000000000
  41. const int maxn=1e6+5;
  42. const ll tle=2e8;
  43. const ll INF=1e9+9;
  44. const int base=31;
  45. string bcc="abcdefghijklmnopqrstuvwxyz";
  46. int dx[]={-1,0,1,0};
  47. int dy[]={0,1,0,-1};
  48. bool sang[10000005];
  49. ll pref[1005][1005],mt[1005][1005];
  50. void sieve(){
  51. for(int i=1;i<=10000000;++i) sang[i]=1;
  52. sang[0]=sang[1]=0;
  53. for(int i=2;i*i<=10000000;++i){
  54. if(sang[i]){
  55. for(int j=i*i;j<=10000000;j+=i) sang[j]=0;
  56. }
  57. }
  58. }
  59. void lis(){
  60. vector<int>t;
  61. vector<int>a;
  62. int n; cin>>n;
  63. for(int i=1;i<=n;++i){
  64. int ai; cin>>ai;
  65. a.pb(ai);
  66. }
  67. for(int x:a){
  68. auto it=lower_bound(all(t),x);
  69. if(it==t.end()) t.pb(x);
  70. else *it=x;
  71. }
  72. }
  73. void pfs2d(){
  74. int n,m,k; cin>>n>>k; m=n;
  75. for(int i=1;i<=n;++i){
  76. for(int j=1;j<=m;++j) cin>>mt[i][j];
  77. }
  78. for(int i=1;i<=n;++i){
  79. for(int j=1;j<=m;++j) pref[i][j]=mt[i][j]+pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1];
  80. }
  81. }
  82. ll qu2d(int x1,int y1,int x2,int y2){
  83. return pref[x2][y2]-pref[x1-1][y2]-pref[x2][y1-1]+pref[x1-1][y1-1];
  84. }
  85. void open(){
  86. if(fopen("deptrai.INP","r")){
  87. mofile("deptrai.INP");
  88. outfile("deptrai.OUT");
  89. }
  90. }
  91. ll a[maxn],b[maxn],t2[maxn];
  92. unordered_map<int,int>f;
  93. ll kq=0;
  94. int main(){
  95. fast;
  96. int n; cin>>n;
  97. for(int i=1;i<=n;++i) cin>>a[i];
  98. if(n<=6){
  99. ll s=0;
  100. for(int i=1;i<=n;++i) s+=a[i];
  101. cout<<s<<"\n";
  102. het;
  103. }
  104. ll cur1=0,cur2=0,cur3=0;
  105. ll b1=-INF,b2=-INF,b3=-INF;
  106. for(int i=1;i<=n;++i){
  107. cur3=max(cur3+a[i],b2+a[i]);
  108. b3=max(b3,cur3);
  109. cur2=max(cur2+a[i],b1+a[i]);
  110. b2=max(b2,cur2);
  111. cur1=max(cur1+a[i],a[i]);
  112. b1=max(b1,cur1);
  113. }
  114. cout<<b3<<"\n";
  115. het;
  116. }
  117. // Remember case n <= 6.
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0