prompt
string
response
string
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
//package round407; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); int...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(input()) arr=list(map(int,input().split())) new=[] c=1 for i in range(n-1): new.append(abs(arr[i]-arr[i+1])*c) c*=-1 s=0 s1=0 m=0 for i in range(n-1): s+=new[i] if s<0: s=0 if i>0: s1+=-new[i] if s1<0: s1=0 m=max(m,s1) m=max(m,s) print(m)
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long INF = 1e9; const long long LINF = (long long)1e16 + 5; int main() { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int sub[n - 1]; for (int i = 0; i < n - 1; i++) { if (...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque from bisect import bisect_left,bisect_right n=int(input()) l=list(map(int,input().split())) z=[] for i in range(n-1): z.append(abs(l[i]-l[i+1])) ans=0 a,b=0,0 for i in z: a,b=max(b+i,0)...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = map(int, raw_input().split()) tab = map(int, raw_input().split()) acc = 0 mx = 0 mn = 0 k = 1 for i in range(len(tab)-1): acc += abs(tab[i] - tab[i + 1]) * k k *= (-1) mx = max(mx, acc) mn = min(mn, acc) print abs(mx-mn)
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> const int N = 100010; int a[N], _abs[N], n; std::multiset<long long> set = {0}; long long pre[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); _abs[i] = std::abs(a[i - 1] - a[i]); } for (int i = 1; i < n; ++i) { pre[i] = pre[i - 1] + (i & 1...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=input() a=map(int,raw_input().split()) b=[abs(a[i]-a[i-1]) for i in range(1,n)] a=b[0] s=t=0 for i in range(n-1): d=(b[i],-b[i])[i%2] s+=d t-=d a=max(a,s,t) s=max(s,0) t=max(t,0) print a
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; import java.math.*; public class Main{ /* . . . . . . . some constants . */ /* . . . if any . . */ public static void main(String[] args) throws IOException{ /* . . . . . . */ int n=ni(); long arr[]=nla(n); long...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def solve(): n = int(input()) a = tuple(map(int, input().split())) d = [] for i in range(0, n - 1): d.append(abs(a[i] - a[i + 1])) subtracted = [0 for i in range(n - 1)] added = [0 for i in range(n - 1)] if n == 2: print(d[0]) else: added[0] = d[0] ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import sys n=int(input()) l=list(map(int,input().split())) a=[0]*(n-1) for i in range(n-1): a[i]=abs(l[i]-l[i+1])*(-1)**(i) if n==2: print(a[0]) sys.exit() a1=[0]*(n-2) for i in range(1,n-1): a1[i-1]=abs(l[i]-l[i+1])*(-1)**(i-1) ans=a[0] cur=a[0] for i in range(1,n-1): cur=max(cur+a[i],a[i]) an...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) A = list(map(int, input().split())) B = [] for i in range(n - 1): B.append(abs(A[i] - A[i + 1])) dpmin = [0] * n dpmax = [0] * n for i in range(n - 2, -1, -1): dpmax[i] = B[i] dpmin[i] = B[i] dpmin[i] = min(dpmin[i], B[i] - dpmax[i + 1]) dpmax[i] = max(dpmax[i], B[i] - dpmin[i + 1])...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; public class Functions_again { public static void main(String args[]) throws Exception { BufferedReader f=new BufferedReader(new InputStreamReader(System.in)); int size=Integer.parseInt(f.readLine()); long[][] dp=new long[size][2]; int[] arr=new int[size]; StringTokeniz...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.*; public class C { public static void main(String[] args)throws Throwable { MyScanner sc=new MyScanner(); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int [] a=new int [n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); long [] b=new long [n-1]; int p...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(input()) a=list(map(int, input().split(" "))) d=[] for k in range(n-1): d.append(abs(a[k]-a[k+1])) for k in range(n-1): if(k%2): d[k]*=-1 maxsum=0 minsum=0 curmax=0 curmin=0 for k in range(n-1): if(d[k]>0): minsum=min(curmin, minsum) curmax+=d[k] curmin+=d[k] if(curmin>0): curmin=0 ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class FunctionsAgain_CF788A { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(Sy...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.InputStream; import java.io.BufferedReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.math.BigDecimal; import java.util.*; import java.util.stream.Str...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) a = list(map(int, input().split())) d = [[] for i in range(2)] pre = a[0] mi = 1 for i in range(1, n): d[0].append(mi * abs(pre - a[i])) d[1].append(-mi * abs(pre - a[i])) pre = a[i] mi *= -1 m = len(d[0]) L = [[0] * m for i in range(2)] R = [[0] * m for i in range(2)] L[0][0] = d[0][0...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; struct DP_NODE { long long int maxval, minval; }; DP_NODE dp[200005]; long long int a[200005]; int n; int main(int argc, char* argv[]) { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]); dp[n - 2].maxval = abs(a[n - 2] - a[n - 1]); dp[n - 2].minv...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int INF = 0x3f3f3f3f; inline long long lllabs(long long x) { return x < 0 ? -x : x; } long long a[N]; int main() { int n; while (~scanf("%d", &n)) { a[0] = 0; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 2; i <=...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long arr[100005], dif[100005]; int main() { long long n, i; cin >> n; for (i = 0; i < n; i++) cin >> arr[i]; for (i = 0; i < n - 1; i++) { dif[i] = abs(arr[i] - arr[i + 1]); } for (i = 0; i < n - 1; i++) { if (i & 1) dif[i] = -dif[i]; } long lon...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.*; /** * @author Aydar Gizatullin a.k.a. lightning95, aydar.gizatullin@gmail.com * Created on 17.02.17. */ public class Main { class Pair { int a, b; Pair(int x, int y) { a = x; b = y; } } private void solve()...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; int main() { long long int a[MAX], dif[MAX], n, i; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i < n; i++) { if (i % 2) dif[i] = dif[i - 1] + abs(a[i] - a[i + 1]); else dif[i] = dif[i - 1] - abs(...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> vec(n + 1); for (long long i = 1; i <= n; i++) cin >> vec[i]; vec[0] = vec[1]; long long dp[2][n], x; memset(dp, 0, sizeof(dp)); long long ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def maxSubArraySum(a,size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if max_ending_here < 0: max_ending_here = 0 # Do not compare for all elements. Compare only # when ma...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; public class Solution{ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n; long long int a[N], b[N], s1[N], s2[N], mns, ans; long long maxSubArraySum(long long x[], int siz) { long long max_so_far = x[1]; long long curr_max = x[1]; for (int i = 2; i < siz; i++) { curr_max = max(x[i], curr_max + x[i]); max...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; inline char tc(void) { static char fl[10000], *A = fl, *B = fl; return A == B && (B = (A = fl) + fread(fl, 1, 10000, stdin), A == B) ? EOF : *A++; } inline int read(void) { int a = 0, f = 1; char...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int a[100005], p[100005]; long long z = 1, f[100005][2], ans; int main() { int i, j, n, m; memset(f, 0xc0, sizeof(f)); scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i <= n; i++) p[i] = abs(a[i + 1] - a[i]); f[1][1] = p[1]; ans = p[1...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; public class C789 { public static void main(String[] args) { InputReader s = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); /*My code starts here.*/ int n = s.nextInt(); long arr[] = new long[n-1]; long prev = s.nextInt(); long max = -1...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long f[n - 1]; long long s[n - 1]; for (long long i = 0; i < n - 1; i++) { f[i] = abs((a[i] - a[i + 1])) *...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
# Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase def solve(d): ma, mas = 0, 0 for i in d: mas += i mas = max(mas, 0) ma = max(mas, ma) return ma def main(): n=int(input()) a=list(map(int,input().split())) ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long v[200050], sp1[200050], sp2[200050]; int main() { int n, i, k, first, iteratii = 0; long long minsp1 = 0, minsp2 = 0, ans = -0x3f3f3f3fLL; cin >> n; for (i = 1; i <= n; ++i) cin >> v[i]; for (i = 1; i < n; ++i) { sp1[i] = sp1[i - 1] + abs(v[i] - v[i ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.Scanner; public class Frodo { static long max(int[] a) { long maxsofar = 0, maxhere = 0; for (int i = 0; i < a.length; i++) { maxhere = Math.max(maxhere + a[i], 0); maxsofar = Math.max(maxsofar, maxhere); } return maxsofar; } static int[] arr, a1, a2; public static void main(String...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.File; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.Writer; ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import sys import math n = int(sys.stdin.readline().strip()) a=map(int,sys.stdin.readline().split()) v=[] for i in range(n-1): v.append(abs(a[i]-a[i+1])) sm=0 mx=0 for i in range(n-1): if i%2==0: sm+=v[i] else: sm-=v[i] if sm>mx:mx=sm if sm<0:sm=0 sm=0 for i in range(n-1): if i%2=...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int n; vector<long long int> v; long long int im[2][100002]; long long int mx[2][100002]; int main() { cin >> n; for (int i = 0; i < n; i++) { int a; scanf("%d", &a); v.push_back(a); } for (int i = 0; i + 1 < v.size(); i++) { for (int j = 0; j < 2; j...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) l = list(map(int, input().split(" "))) d = [] for i in range(n-1): a = 1 if i%2: a = -1 d.append(a*(abs(l[i]-l[i+1]))) s, b = 0, 0 sm, bm = 0, 0 for i in range(n-1): s = max(d[i], s + d[i]) b = max(s, b) for i in range(1, n-1): sm = min(d[i], sm + d[i]) bm = min(sm...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; public class Practice { //static int a[], b[],c[]; //static long d[]; //static int m,ans; //static ArrayList<Integer> adj[]; //static int cat[]; //static boolean visited[]; static boolean b[]; public static void main(String[] args) { in=new InputReader(System.in); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> int n; long long arr[100100]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", arr + i); std::vector<long long> a; for (int i = 0; i < n - 1; i++) { a.push_back(arr[i + 1] - arr[i]); if (a[a.size() - 1] < 0) a[a.size() - 1] *= -1; } long long max = a[0...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = input() a = map(int, raw_input().split()) dp = [[0, 0] for i in xrange(n)] dp[1][0] = abs(a[1] - a[0]) dp[1][1] = 0 ans = dp[1][0] for i in xrange(2, n): dp[i][0] = max(abs(a[i] - a[i - 1]), dp[i - 1][1] + abs(a[i] - a[i - 1])) dp[i][1] = max(0, dp[i - 1][0] - abs(a[i] - a[i - 1])) ans = max(ans, dp[i][0], dp[...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import bisect import decimal from decimal import Decimal import os from collections import Counter import bisect from collections import defaultdict import math import random import heapq from math import sqrt import sys from functools import reduce, cmp_to_key from collections import deque import threading from itert...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static MyScanner in; static long max = -Long.MAX_VALUE, start = -1, end = -1; public static void main(String[] args) throws Exception { in = new MyScanner(); int n = in.nextInt(); in...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; public class fagain { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long m = 0; long e = 0; long o = 0; long x = sc.nextInt(); long y; long d; for (int k = 0; k < n-1; k++) { ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(input()) l=list(map(int,input().split())) arr=[] for i in range(n-1): if i%2==0: arr.append(abs(-l[i+1]+l[i])) else: arr.append(-(abs(-l[i+1]+l[i]))) arr1=[] for i in range(n-1): if i%2==1: arr1.append(abs(-l[i+1]+l[i])) else: arr1.append(-(abs(-l[i+1]+l[i]))) pre1=...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { int j = -1, i, x, y, n; cin >> n; long long t[n], s = 0; cin >> x; for (i = 0; i < n - 1; i++) { cin >> y; j *= -1; s += j * (abs(x - y)); t[i] = s; x = y; } sort(t, t + n - 1); if (t[0] >= 0) cout << t[n - 2]; else ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; long long a[N], d[N], f[N][2], n, ans; int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i < n; i++) d[i] = abs(a[i] - a[i + 1]); for (int i = 1; i < n; i++) { f[i][0] = max(f[i - 1][1] + ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.concurrent.ConcurrentSkipListSet; public class Main { public static void main(String[] args) throws FileNotFoundException { ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out)); // ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class C { static void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; void MAIN(); int main() { MAIN(); return 0; } const int N = (int)1e5 + 32; int n, a[N]; long long f[N]; long long opt1, opt2, ans = -(1LL << 60); void MAIN() { scanf("%d", &n); for (int i = 0; i < (int)(n); i++) scanf("%d", a + i); for (int i = n - 2; i >= 0; i--)...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i = 0; i < n - 1; i++) v[i] = (i & 1) ? -(llabs(v[i] - v[i + 1])) : llabs(v[i] - v[i + ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
# !/bin/env python3 # encoding: UTF-8 # βœͺ H4WK3yEδΉ‘ # Mohd. Farhan Tahir # Indian Institute Of Information Technology and Management,Gwalior # Question Link # https://codeforces.com/problemset/problem/788/A # # ///==========Libraries, Constants and Functions=============/// import sys inf = float("inf") mod = 100...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") bool iseven(long long int n) { if ((n & 1) == 0) return true; return false; } void print(long long int t) { cout << t; } void print(int t) { cout << t; } void print(string t) { cout << t; } void print(char...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
from collections import defaultdict from sys import stdin def fun(ar): if(len(ar)) < 2: return 0 ans, cur = 0, 0 for i in range(len(ar)-1): if (i & 1) == 0 and cur < 0: cur = 0 cur += abs(ar[i+1]-ar[i])*(-1 if i & 1 else 1) ans = max(ans, cur) return ans def main(): n = int(stdin.readline()) ar = li...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(input()) a=list(map(int,input().split())) da,p=[],1 for i in range(n-1): da.append(p*abs(a[i]-a[i+1]));p*=-1 m1,m2,s1,s2=0,0,0,0 for x in da: s1+=x if s1<0: s1=0 s2-=x if s2<0: s2=0 m1=max(m1,s1);m2=max(m2,s2) print(max(m1,m2))
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long dp[100005][3][3][3]; bool vis[100005][3][3][3]; long long arr[100005]; int n; long long best(int i, int st, int prev, int seq) { if (st > 1) return 0; if (i == n) return 0; long long& ret = dp[i][st][prev][seq]; if (vis[i][st][prev][seq] != 0) return ret; ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class C789 { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readL...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; public class functionAgain { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long a=sc.nextLong(); long max=0; long min=0; long s=0; for(int i=1;i<n;i++) { long b=sc.nextLo...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T qmin(const T a, const T b) { return a < b ? a : b; } template <typename T> inline T qmax(const T a, const T b) { return a > b ? a : b; } template <typename T> inline void getmin(T &a, const T b) { if (a > b) a = b; } template <typename T...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def maxSubArraySum(a, size): max_so_far = a[0] curr_max = a[0] for i in range(1, size): curr_max = max(a[i], curr_max + a[i]) max_so_far = max(max_so_far, curr_max) return max_so_far n = int(input()) l = list(map(int,input().split())) o = [] p = [] m = 0 i = 0 while(i < len(l)-1): ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> const long long mod = 1000000007L; using namespace std; long long ar[200010], t1[200010], t2[200010]; int n; long long solve(long long p[]) { long long sum = p[0]; long long ans = p[0]; for (int i = 1; i < n - 1; i++) { if (sum < 0) sum = p[i]; else sum += p[i]; an...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; public class Main { static long INF = Long.MAX_VALUE; public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; } template <typ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long arr[100010]; int n; long long asol[100010]; long long nokol[100010]; int main() { cin >> n; for (int i = 0; i <= n - 1; i++) { scanf("%I64d", &arr[i]); } for (int i = 0; i <= n - 2; i++) { asol[i] = abs(arr[i + 1] - arr[i]); nokol[i] = asol[i];...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long ma, mi, ans, s[500001], a[500001]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); long long ma = -1e9, mi = 1e9; for (int i = 2; i <= n; i++) { s[i] = s[i - 1] + abs(a[i] - a[i - 1]) * (i & 1 ? -1 : 1); ma =...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.Scanner; /** * Created by lenovo on 1/29/2018. */ public class M788A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] input = new int[n]; for (int i = 0; i < n; ++ i) { inpu...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { private static FastReader fastReader = new FastReader(); private static FastWriter fastWriter = ne...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Hash...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; void _print(long long int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } template <class T, class V> vo...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def getNum(): inp = input() return int(inp) def getArrNum(): inp = input() A = [int(x) for x in inp.split(' ')] return A def getMaximal(arr): best = 0 curBest = 0 for x in arr: if curBest>=0: curBest += x else: curBest = x best = max(...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N]; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; long long sum = 0; long long maxSum = -1e14; for (int i = 0; i + 1 < n; i++) { if ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<long long> a(n); for (auto &it : a) cin >> it; ; long long ans = -1e18, sum = 0; for (int i = 0; i < n - 1; i++) { if (i % 2 == 0) { sum += abs(a[i] - a[i + 1]); } else { sum -= abs(a[i] - a[i + 1]); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long a[100005]; long long dp[100005][2]; int main() { int n; while (cin >> n) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) cin >> a[i]; int x = 1; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] + x * abs(a[i] - a[i - 1]); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def maxSubArray( A): if not A: return 0 curSum = maxSum = A[0] for num in A[1:]: curSum = max(num, curSum + num) maxSum = max(maxSum, curSum) return maxSum n = int(input()) L = list(map(int, input().split())) D1 = [] D2 = [] for i in range(1, len(L)): D1.append(abs(L[i] ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; import java.util.stream.Collectors; public class Main { public static void main(String[] args) throws IOException { IO io = new IO(); int n = io.getInt(); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def kadane(arr): max_ending_here = 0 max_so_far = 0 for i in arr: max_ending_here += i if max_ending_here < 0: max_ending_here = 0 if max_so_far < max_ending_here: max_so_far = max_ending_here return max_so_far n = int(raw_input()) array = map(int ,raw_i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long a[100005], b[100005], c[100005]; int main() { long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; long long maxi = 0, mini = 0, res = 0; for (long long i = 0; i < n - 1; i++) { long long x = abs(a[i] - a[i + 1]); long long minia...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], c[100005]; long long maxsum(int x[], int s) { long long m = 0; long long l = 0; for (int i = 0; i < s; i++) { l = l + 1ll * x[i]; if (l > m) m = l; if (l < 0) l = 0; } return m; } int main() { int n, i; scanf("%d", &n); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) a = list(map(int, input().split())) dif = list() for i in range(n-1): if(i%2==0): dif.append(int(abs(a[i] - a[i+1]))) else: dif.append(-1 * int(abs(a[i] - a[i+1]))) #print('dif = ', dif) pref = list() for i in range(len(dif)): if(i==0): pref.append(dif[0]) else: ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long a[(int)1e5 + 30], b[(int)1e5 + 30], dp[(int)1e5 + 30], dp2[(int)1e5 + 30]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { b[i] = abs(a[i] - a[i - 1]); } long long ans = -1, res = 0; for (i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) a = list(map(int, input().split())) b = [0] * n c = [0] * n for i in range(n - 1): x = abs(a[i] - a[i + 1]) if i % 2 == 0: b[i] = x c[i] = -x else: b[i] = -x c[i] = x def maxSubArray(arr): best = 0 current = 0 for x in arr: current = max(0...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import sys from collections import Counter #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt','w') N = int(raw_input().strip()) A = map(int, raw_input().strip().split(' ')) A = [abs(A[i]-A[i+1]) for i in xrange(N-1)] dpplus = [0]*(N-1) dpminus = [0]*(N-1) dpplus[0],dpminus[0] = A[0],-A[0] for i in xra...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
c = lambda:map(int, raw_input().split()) n = input() a = c() b, c = [0], 1 for i in range(1, n): b.append(abs(a[i] - a[i - 1]) * c) c = -c x, y, s, m = 0, 0, 0, 0 for i in range(1, n): s += b[i] x = min(x, s) y = max(y, s) m = max(m, y - x) print m
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long kadane(vector<long long> &a) { long long max_sum = INT_MIN, curr_sum = 0; for (long long i = 0; i < (long long)a.size(); i++) { curr_sum += a[i]; if (curr_sum < 0) curr_sum = 0; max_sum = max(max_sum, curr_sum); } return max_sum; } int32_t main...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, a[100005], b[100005], c[100005]; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; b[0] = 0, c[0] = 0; for (int i = 1; i < n; i++) { if (i % 2 == 0) b[i] = b[i -...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
//package baobab; import java.io.*; import java.util.*; public class C { public static void main(String[] args) { HashSet<Long> bad = new HashSet<>(); Solver solver = new Solver(); } static class Solver { IO io; public Solver() { this.io = new IO(); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(raw_input()) a = map(int, raw_input().split()) diffs = [max(a[i]-a[i+1], a[i+1]-a[i]) for i in range(len(a)-1)] max_best = 0 max_to_here1 = 0 max_to_here2 = 0 #print(diffs) for i in range(len(diffs)): max_to_here1 =max(0, max_to_here1+ diffs[i] *(-1)**i) max_to_here2 =max(0, max_to_here2 +diffs[i] * (-...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
from itertools import accumulate inf = 10**9 + 1 def solve(): n = int(input()) a = [int(i) for i in input().split()] ad = [abs(a[i + 1] - a[i]) for i in range(n - 1)] ap = [0] + list(accumulate(ai*(-1)**i for i, ai in enumerate(ad))) max_dif, max_mdif = max_min_profit(ap) ans = max(max_dif, m...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; wh...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long int kadane(vector<long long int> v) { if (v.size() == 0) return INT_MIN; long long int n = v.size(); long long int curr_max = v[0], ans = v[0]; for (int i = 1; i < n; i++) { curr_max = max(curr_max + v[i], v[i]); ans = max(curr_max, ans); } ret...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) a = list(map(int, input().split())) d = [abs(a[i] - a[i+1]) * (-1)**i for i in range(n-1)] maxsum1 = 0 sum1 = 0 for di in d: if di > 0 or abs(di) < abs(sum1): sum1 += di else: sum1 = 0 maxsum1 = max(maxsum1, abs(sum1)) sum1 = 0 for di in d[1:]: if di < 0 or abs(di) < abs...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import static java.lang.Math.max; import static java.lang.Math.abs; public class Code_788A_FunctionsAgain { public static void main(String[] args) throws IOExc...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; long long sum = 0, z = 0, s = 0, m = 0, mm = 0; cin >> n; vector<long long> a(n); for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < (n - 1); i++) { if (i % 2 == 0) sum = sum + abs(a[i + 1] - a[i]); else sum = max(z, ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class c { public static void main(String[] args) throws NumberFormatException, IOException { FastScanner in = new FastScanner(S...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(raw_input()) N=map(int,raw_input().split()) b=[] c=[] ans=0 for i in range(1,n): b.append(abs(N[i]-N[i-1])) c.append(abs(N[i-1]-N[i])) for i in range(len(b)): if i%2!=0: b[i]= -b[i] else: c[i]= -c[i] maxso= -(10**20)-1 maxe=0 for i in range(len(b)): maxe=maxe+b[i] if maxso<maxe: maxso=maxe if maxe<0:...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") const long long INF = 1e18 + 1LL; const double Pi = acos(-1.0); const int N = 1e5 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9; int n, a[N], b[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d"...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class A { static StringTokenizer st; static BufferedReader br; static PrintWriter pw; ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<long long int> b(n), c(n); b[n - 1] = 0, c[n - 1] = 0; b[n - 2] = abs(a[n - 2] - a[n - 1]); c[n - 2] = b[n - 2]; if (n > 2) { b[n - 3] = abs(a[n - 3] - a[n ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class CF788A { public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(); PrintWriter pw = new Print...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long a[105000]; long long b[105000]; long long n; long long gao() { long long x = 0, ret = 0; for (long long i = 1; i < n; i++) { x += b[i]; ret = max(ret, x); if (x < 0) x = 0; } return ret; } signed main() { cin >> n; for (long long i = 1; i <...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 100100; int n; int a[maxn + 5], b[maxn + 5...