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