Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long a[n]; for...
CPP
788_A. Functions again
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 defined as...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Ribhav */ public class Mai...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; vector<long long int> a(n), b; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 1; i < n; i++) b.push_back(abs(a[i] - a[i - 1])); n = b.size(); long long int dp[n][2]; dp[n - 1][0] = b[n - 1]...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int N; long long a[100000]; void input() { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%I64d", &a[i]); } } long long b[100000]; long long c[100000]; long long maxSumSubarr() { long long sum = c[0]; long long max_sum = sum; for (int i = 1; i < N - 1...
CPP
788_A. Functions again
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 defined as...
2
7
import java.util.*; import java.lang.*; import java.io.*; public class Prac { public static long max(long a,long b){ if(a>b) return a; else return b; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); ...
JAVA
788_A. Functions again
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 defined as...
2
7
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class Main { ...
JAVA
788_A. Functions again
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 defined as...
2
7
def max_sum(a): s, ans = 0, 0 for i in a: s += i ans = max(s, ans) s = max(0, s) return ans n = int(input()) *a, = map(int, input().split()) a = [abs(a[i] - a[i + 1]) for i in range(n - 1)] b = [-1 * a[i] if i & 1 else a[i] for i in range(n - 1)] a = [a[i] if i & 1 else -1 * a[i] for...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long was[211111][2]; int a[211111]; int n; long long f(int x, int o) { if (was[x][o]) return was[x][o] - 1; long long ret = 0; if (x + 1 < n) { long long val = f(x + 1, o ^ 1); if (o == 0) val += abs(a[x + 1] - a[x]); else val -= abs(a[x +...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(input()) arr = list(map(int,input().split())) even = [0 for i in range(n)] odd = [0 for i in range(n)] diff = [] for i in range(n-1): diff.append(abs(arr[i]-arr[i+1])) for i in range(len(diff)): even[i] = max(diff[i],diff[i]+odd[i-1]) odd[i] = max(-diff[i],-diff[i]+even[i-1]) print(max(max(even),max...
PYTHON3
788_A. Functions again
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 defined as...
2
7
// Don't place your source in a package import java.util.*; import java.lang.*; import java.io.*; import java.math.*; // Please name your class Main public class Main { //static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); /*static int read() throw...
JAVA
788_A. Functions again
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 defined as...
2
7
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)) # Made By Mostafa_Khaled
PYTHON3
788_A. Functions again
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 defined as...
2
7
n = int(input()) a = list(map(int, input().split())) first = [-abs(a[i]-a[i-1]) if (i+1)%2 else abs(a[i]-a[i-1]) for i in range(1, n)] second = [abs(a[i]-a[i-1]) if (i+1)%2 else -abs(a[i]-a[i-1]) for i in range(2, n)] mx = -10**18 cur = 0 for i in range(len(first)): cur = first[i] + max(cur, 0) if i%2 == 0: ...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int inf = (int)1e9 + 10; const int mod = (int)1e9 + 7; const double eps = 1e-7; const double pi = 3.14159265359; const int maxLen = (int)1e5 + 2; int A[maxLen]; long long D[maxLen]; int main() { int n; scanf("%d", &n); ...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, i, s = 0, m = 0, x = 0, y = 0, l = 0; cin >> n; vector<long long> a(n); for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) a[i] = abs(a[i] - a[i + 1]); for (i = 0; i ...
CPP
788_A. Functions again
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 defined as...
2
7
import java.io.*; import java.util.*; public class test { int INF = (int)1e9; long MOD = 1000000007; void solve(InputReader in, PrintWriter out) throws IOException { int n = in.nextInt(); long[] a = new long[n]; for(int i=0; i<n; i++) { a[i] = in.nextInt(); ...
JAVA
788_A. Functions again
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 defined as...
2
7
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...
JAVA
788_A. Functions again
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 defined as...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class CFD { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; final long MOD = 1000L * 1000L * 1000L +...
JAVA
788_A. Functions again
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 defined as...
2
7
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, min_dif = max_min_profit(ap) ans = max(max_dif, -m...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll OO = 1e18; int di[8] = {0, 0, 1, -1, -1, 1, -1, 1}; int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1}; string ys = "YES", no = "NO"; const long double dgr = acos(-1) / 180, dg = 180 / acos(-1); const int mod = 1e9 + 7, N = 5e5 + ...
CPP
788_A. Functions again
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 defined as...
2
7
import java.io.*; import java.util.*; public class TestClass { static PrintWriter out = new PrintWriter(System.out); public static void main(String args[]) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); String s[] = in.rea...
JAVA
788_A. Functions again
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 defined as...
2
7
import java.util.*; import java.io.*; public class Forces{ public static void main(String ...arg) { Read cin = new Read(); int n = cin.nextInt(); Long even[] = new Long[n-1]; Long odd[] = new Long[n-1]; long a = cin.nextLong(); long b = a; int sign; long val; for(int i=0;i<n-1;i++) { a = b;...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long a[100010]; long long b[100010]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n - 1; i++) { b[i] = abs(a[i] - a[i + 1]); if (i % 2 == 0) b[i] *= -1; } long long x = 0, ans = 0; for (int...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int inf = (int)1e9 + 10; const int mod = (int)1e9 + 7; const double eps = 1e-7; const double pi = 3.14159265359; const int maxLen = (int)1e5 + 2; int A[maxLen]; long long D[maxLen]; int main() { int n; scanf("%d", &n); ...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int N, A[100500]; long long B[100500]; long long tbs[100500], tbb[100500]; long long ans = (long long)-1e18; int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); } for (int i = 1; i < N; i++) { B[i] = A[i] - A[i + 1]; if (B[i]...
CPP
788_A. Functions again
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 defined as...
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); InputReader inputReader = new InputReader(in); ...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long getBrute(vector<long long> &a) { long long n = a.size(); long long ans = -INF; for (long long l = 0; l < n; l++) { long long cur = 0; for (long long r = l + 1; r < n; r++) { if ((r - l) % 2 == 1) { cur += abs...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(raw_input()) a = [int(x) for x in raw_input().split()] def drawdown(l): cumsum = 0 min_x = 0 answer = 0 for i,val in enumerate(l): if i%2 == 0: min_x = min(min_x, cumsum) cumsum += val answer = max(answer, cumsum - min_x) return answer poso = [abs(a[i]-a[i+1])*(-1)**i for i in range(n-1)] nego =...
PYTHON
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; void fun() { int n; cin >> n; long long a[n]; for (auto &i : a) cin >> i; vector<long long> s; for (int i = 1; i < n; i++) s.push_back(abs(a[i] - a[i - 1])); long long dpn[n - 1], dpp[n - 1]; dpp[0] = s[0]; dpn[0] = -s[0]; for (int i = 1; i < n - 1; i++)...
CPP
788_A. Functions again
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 defined as...
2
7
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, min_dif = max_min_profit(ap) ans = max(max_dif, -m...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int N = 100010; map<long long, int> mp; int main() { long long n, i; long long a[100010], b[100010]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%lld", &a[i]); if (i >= 1) b[i] = abs(a[i] - a[i - 1]); } long long ans = 0; long long maxx = b...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(input()) _l = list(map(int, input().split())) l = [abs(_l[i] - _l[i + 1]) for i in range(n - 1)] p, n, res = 0, 0, 0 for e in l: _p = max(0, n + e) _n = max(0, p - e) p, n = _p, _n res = max(p, n, res) print(res)
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long const N = 1e6 + 5; long long dp[N][2], a[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; n--; for (int i = 0; i < n; i++) a[i] = abs(a[i] - a[i + 1]); long long mx = a...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAX_N = 1e5 + 10; const long long mod = 1e9 + 9; const double PI = acos(-1); int num[MAX_N]; long long dp[MAX_N]; int ab(int x) { return x > 0 ? x : -x; } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d...
CPP
788_A. Functions again
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 defined as...
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long fastPow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret *= a; a *= a; b >>= 1; } return ret; } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n, e, o, ce, co, ret = INT_MIN, c; cin >...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n - 1; i++) { arr[i] = abs(arr[i] - arr[i + 1]); } vector<long long> a(n), b(n); a[0] = arr[0]; long long ans1 = a[0], ans2 = 0; fo...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, INF = 0x7F; long long n, a[maxn], f[maxn], sum[maxn], Max = -INF, Min = INF; int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); Max = max(Max, 0ll); Min = min(Min, 0ll); for (int i = 1; i < n; i++) { f[...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(raw_input()) arr = map(int,raw_input().split()) arr1 = [] arr2 = [] for i in range(n-1): if i%2 == 0: arr1.append(abs(arr[i]-arr[i+1])) arr2.append(-abs(arr[i]-arr[i+1])) else: arr1.append(-abs(arr[i]-arr[i+1])) arr2.append(abs(arr[i]-arr[i+1])) max1 = arr1[0] curMax = arr1[0] for i in range(1,n-...
PYTHON
788_A. Functions again
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 defined as...
2
7
n = int(input()) l = tuple(map(int, input().split())) a = [] for i in range(n - 1): a.append(abs(l[i] - l[i + 1])) ev = [(a[i] if i % 2 == 0 else -a[i]) for i in range(n - 1)] od = [-i for i in ev] od[0] = 0 dp = [ev[0]] st = ["ev"] # print(a) # print(ev) # print(od) vmax = dp[0] evsum = evans = 0 odsum = oda...
PYTHON3
788_A. Functions again
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 defined as...
2
7
import java.io.*; import java.util.*; public class C { static StringBuilder st = new StringBuilder(); static int n ; static long [][] memo ; static int [] a ; static long dp(int idx , int neg) { if(idx == n - 1) return 0 ; if(memo[neg][idx] != -1)return memo[neg][idx] ; long diff = (neg ==...
JAVA
788_A. Functions again
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 defined as...
2
7
import java.io.*; import java.text.DecimalFormat; import java.util.*; public class tennis { static boolean DEBUG_FLAG = false; int INF = (int)1e9; long MOD = 1000000007; long p = 101; long ans = 0; static void debug(String s) { if(DEBUG_FLAG) { System.out.print(s); } ...
JAVA
788_A. Functions again
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 defined as...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.*; import java.math.*; import java.util.*; public class Main { static FastReader in; static PrintWriter o; public static void solve() {...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long int a[1000005]; long long int dp[1000005][2]; int main() { long long int n; scanf("%lld", &n); for (long long int i = 1; i <= (long long int)n; i++) scanf("%lld", a + i); dp[1][0] = abs(a[1] - a[1 + 1]); dp[1][1] = -abs(a[1] - a[1 + 1]); long long int ...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const long long INF = 200000000000000000LL; long long kadane(vector<long long> v) { long long sum = 0; long long ans = sum; for (long long i : v) { sum = max(sum + i, i); ans = max(ans, sum); } return ans; } int main() { int n; scanf("%d", &n); vecto...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long flag(vector<long long> &); int main() { vector<long long> a, b; long long n, x, y, sum = 0, s, q; cin >> n; for (int i = 1; i != n + 1; ++i) { if (i == 1) { cin >> x; continue; } cin >> y; q = y - x; if (q < 0) q = -q; i...
CPP
788_A. Functions again
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 defined as...
2
7
/** * Created by sachgoya on 2/24/2017. */ import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; /** * Created by sachin.goyal on 07/02/17. */ public class C { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = Syste...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int const oo = 1e9, bound = 1e6 + 1, mod = oo + 7; long long const OO = 1e18; int n; int aa[bound]; long long dp[bound][3][2]; long long rec(int idx, int tk, int sg) { long long &ret = dp[idx][tk][sg]; if (ret != -1) return ret; if (idx == n - 1) return ret = 0; if ...
CPP
788_A. Functions again
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 defined as...
2
7
n=input() lst=map(int,raw_input().split()) lst2=[] lst3=[] for i in range(0,n-1): vr=abs(lst[i+1]-lst[i])*(pow(-1,i)) lst2.append(vr) lst3.append(-1*vr) # Python program to find maximum contiguous subarray # Function to find the maximum contiguous subarray from sys import maxint def maxSubArraySum(a,size...
PYTHON
788_A. Functions again
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 defined as...
2
7
n = input() a = map(int,raw_input().split()) ans = 0 #even indexed p = 0 x = 1 cursum = 0 while p < len(a)-1: cursum += abs(a[p]-a[p+1]) * x if cursum < 0: cursum = 0 if p % 2 != 0: p += 1 else: p += 2 x = 1 else: ans = max(ans,c...
PYTHON
788_A. Functions again
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 defined as...
2
7
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))) am = [0] + list(accumulate(ai*(-1)**(i + 1) for i, ai in enumer...
PYTHON3
788_A. Functions again
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 defined as...
2
7
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.PriorityQueue; public final class CF_407_Functions { static void log(int[] X){ int L=X.length; for (int i=0;i<L;i++){ logWln(X[i]+" "); } log(""); } static voi...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long int cal(vector<int> f) { long long int sum = 0; long long int cur = 0; for (int i = 0; i < f.size(); ++i) { cur += f[i]; if (cur < 0) { cur = 0; } if (cur > sum) { sum = cur; } } return sum; } int main() { ios_base::sync...
CPP
788_A. Functions again
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 defined as...
2
7
import math def findmax(a): c = ret = a[0] for i in range(1, len(a)): c = max(a[i], c + a[i]) ret = max(ret, c) return ret n = int(raw_input()) a = map(int, raw_input().split()) p = [] np = [] m = 1 for i in range(len(a) - 1): p.append(abs(a[i] - a[i + 1]) * m) m *= -1 if i > 0:...
PYTHON
788_A. Functions again
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 defined as...
2
7
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 Abood2C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); Prin...
JAVA
788_A. Functions again
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 defined as...
2
7
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 Codeforces { public static void main(String[] args) { InputStream inputStream = S...
JAVA
788_A. Functions again
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 defined as...
2
7
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java....
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 5; long long v[MAXN]; long long a[MAXN]; long long dp[MAXN][2]; int m; inline int sign(int x) { if (x == 0) { return 1; } return -1; } long long solve(int pos, int flag) { if (pos >= m) { return 0; } if (dp[pos][flag] != -1) {...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long int n, ans, s = 0, f = 0, arr[100005] = {0}, arr2[100005] = {0}, mx = -10000000000000000; void kadane() { for (int i = 0; i < n - 1; i++) { if (arr2[i] + s < 0) { s = 0; } else { s += arr2[i]; } if (s > mx) { ...
CPP
788_A. Functions again
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 defined as...
2
7
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner x = new Scanner(System.in); int n=x.nextInt(); long arr[] = new long [n]; for(int i=0;i<n;i++){ arr[i]=x.nextLong(); } long[] sum = new long[n-1]; for(int i=0;i<n-1;i++) { sum[i]= Math.abs(arr[i...
JAVA
788_A. Functions again
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 defined as...
2
7
// package codeforces.cf4xx.cf407.div1; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A { public static void main(String[] args) { InputReader in = new InputReader(System.in); Print...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, N[100005]; long long int A[100005]; long long int B[100005]; cin >> n; long long int i; for (i = 1; i <= n; i++) { cin >> N[i]; } for (i = 1; i < n; i++) { long long int k; k = abs(N[i + 1] - N[i]); if (i % 2 == ...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(raw_input()) arr = map(int,raw_input().split()) newarr1 = [] newarr2 = [] one = 1 for i in xrange(n-1): newarr1.append(one*abs(arr[i+1]-arr[i])) newarr2.append(-1*one*abs(arr[i+1]-arr[i])) one*=-1 val = 0 temp = [] for i in xrange(len(newarr1)): if(val+newarr1[i]>0): val += newarr1[i] temp.append(val...
PYTHON
788_A. Functions again
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 defined as...
2
7
def main(): n = int(input()) arr = list(map(int,input().split())) dp = [] ans = -float('inf') total = 0 for i in range(n-1): if i%2 == 0: total += abs(arr[i]-arr[i+1]) else: total -= abs(arr[i]-arr[i+1]) ans = max(ans,abs(arr[i]-arr[i+1])) ...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int ar[n]; for (int i = 0; i < n; i++) { cin >> ar[i]; } int b[n]; for (int i = 0; i < n - 1; i++) { b[i] = abs(ar[i] - ar[i + 1]); if (i...
CPP
788_A. Functions again
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 defined as...
2
7
import java.util.*; public class Functional { public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] arr = new long[n-1]; long last = in.nextLong(); for (int i = 1; i < n; i++) { long current = in.nextLong(); arr[i-1] = Math.abs(last - current); las...
JAVA
788_A. Functions again
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 defined as...
2
7
def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def msi(): return map(str,input().split()) def li(): return list(mi()) n=ii() a=li() dp=[[0,0] for i in range(n)] for i in range(1,n): curr=abs(a[i]-a[i-1]) if dp[i-1][0]>0: dp[i][1]=curr dp[i][0]=...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int main() { vector<long long int> arr, arr2, x, y; int n; long long int temp; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%I64d", &temp); arr.push_back(temp); } for (int i = 0; i < n - 1; i++) { arr2.push_back(abs(arr[i] - arr[i + 1])); ...
CPP
788_A. Functions again
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 defined as...
2
7
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) d = [] for i in range(n-1): if i%2==0: d.append(abs(a[i+1]-a[i])) else: d.append(-abs(a[i+1]-a[i])) ans = -10**18 m = 0 acc = 0 for i in range(n-1): acc += d[i] ans = max(ans, acc-m) i...
PYTHON3
788_A. Functions again
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 defined as...
2
7
read = lambda: map(int, input().split()) n = int(input()) a = list(read()) d = [0] * n b = [0] * n c = [0] * n sgn = 1 for i in range(1, n): d[i] = abs(a[i - 1] - a[i]) b[i] = d[i] * sgn c[i] = -b[i] sgn *= -1 s = [0] * n for i in range(1, n): s[i] = s[i - 1] + b[i] mn = ans = 0 for i in range(1, n)...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:2000000") #pragma comment(linker, "/HEAP:2000000") using namespace std; void print_width(long long x) { std::cout << std::fixed; std::cout << std::setprecision(x); } long long power(long long x, long long y, long long p = 1000000007) { long long res = 1; ...
CPP
788_A. Functions again
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 defined as...
2
7
import java.io.*; import java.util.StringTokenizer; import static java.lang.Math.max; /** * 788A * ΞΈ(n) time * ΞΈ(n) space * * @author artyom */ public class _788A implements Runnable { private BufferedReader in; private StringTokenizer tok; private long solve() throws IOException { int n = ...
JAVA
788_A. Functions again
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 defined as...
2
7
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.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; i...
JAVA
788_A. Functions again
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 defined as...
2
7
n = int(input()) a = list(map(int,input().strip().split())) b = [0]*(n-1) c = [0]*(n-1) for i in range(n-1): if (i)%2 == 0: b[i] = (abs(a[i] - a[i+1])) else: b[i] = (abs(a[i] - a[i+1]))*(-1) for i in range(1,n-1): if (i-1)%2 == 0: c[i] = (abs(a[i] - a[i+1])) else: c[i] ...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int n; long long dat[100002]; long long dif[100002]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> dat[i]; dif[i] = dat[i] - dat[i - 1]; if (dif[i] < 0) dif[i] *= -1; } long long may = INT_MIN; long long aux = 0; long long par = 0; l...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; long long num[maxn]; long long sum[maxn]; long long getmaxsum(long long *s, int n) { long long Max = 0; long long ssum = 0; for (int i = 0; i < n; ++i) { ssum += s[i]; Max = max(ssum, Max); if (ssum < 0) ssum = 0; } return Max...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n - 1): b.append(abs(a[i] - a[i + 1])) mx = -float('inf') now = 0 for i in range(n - 1): now += b[i] * (-1) ** (i % 2) mx = max(mx, now) if now < 0: now = 0 now = 0 for i in range(1, n - 1): now += b[i] * (-1) ** (i %...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long int maxSubArraySum(vector<long long int> a, int size) { long long int max_so_far = 0, max_ending_here = 0, pos = 1; for (int i = 0; i < size; i++) { if ((max_ending_here + a[i]) < a[i]) { max_ending_here = a[i]; pos = 1; } else max_en...
CPP
788_A. Functions again
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 defined as...
2
7
import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.io.PrintWriter; public class C_407 { public static int mod = 1000000007; static FastReader scan = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String args[]...
JAVA
788_A. Functions again
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 defined as...
2
7
n = int(input()) a = list(map(int, input().split())) b = [] f = 1 for i in range(len(a) - 1): b.append(abs(a[i] - a[i + 1]) * f) f *= -1 max1, max2 = 0, 0 a1, a2 = 0, 0 for i in range(n - 1): if a1 + b[i] > 0: a1 += b[i] else: a1 = 0 max1 = max(a1, max1) if a2 - b[i] > 0: ...
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; using pii = pair<long long, long long>; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; vector<long long> b(n); for ...
CPP
788_A. Functions again
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 defined as...
2
7
def f(l, r, p): if l > r: return 0 return p[r] - p[l - 1] if l % 2 == 1 else -f(l - 1, r, p) + p[l - 1] def main(): read = lambda: tuple(map(int, input().split())) n = read()[0] v = read() p = [0] pv = 0 for i in range(n - 1): cp = abs(v[i] - v[i + 1]) * (-1) ** i pv +=...
PYTHON3
788_A. Functions again
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 defined as...
2
7
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner in=new ...
JAVA
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; const long long INF = numeric_limits<long long>::max(); enum { EVEN, ODD }; int A[MAXN]; long long dp[2][MAXN]; int main() { int N; cin >> N; for (int i = 1; i <= N; ++i) cin >> A[i]; dp[ODD][1] = dp[EVEN][1] = dp[ODD][2] = -INF; dp[E...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long int p1(int i) { if (i % 2 == 0) return 1; else return -1; } int main() { long long int n; cin >> n; vector<long long int> a(n + 1, 0), psum(n + 1, -10000000000); for (int i = 1; i < n + 1; i++) scanf("%lld", &a[i]); psum[2] = abs(a[1] - a[2])...
CPP
788_A. Functions again
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 defined as...
2
7
#!/usr/bin/python # coding: utf-8 n=int(raw_input()) arr=map(long,raw_input().split(' ')) arr1=[] for i in xrange(n-1): tmp=abs(arr[i+1]-arr[i]) tmp=tmp*((-1)**i) arr1.append(tmp) arr2=[] for i in xrange(n-1): arr2.append(arr1[i]*(-1)) max=current=0 for i in xrange(n-1): current+=arr1[i] if(c...
PYTHON
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int a[maxn]; long long b[maxn], sum[maxn]; long long getMax(int n) { sum[0] = 0; for (int i = 0; i < n; i++) { sum[i + 1] = sum[i] + b[i]; } long long res = 0; int id = 0; for (int i = 1; i <= n; i++) { if (sum[i] - sum[id] <= 0)...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long a[100005]; long long dp[100005][2]; int main() { long long res, n, k; while (cin >> n) { for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { a[i] = abs(a[i] - a[i + 1]); } long long ans = 0; for (i...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> const int MAXINT = 2147483640; const long long MAXLL = 9223372036854775800LL; const long long MAXN = 1000000; const double pi = 3.1415926535897932384626433832795; using namespace std; long long ans = -MAXINT, n; long long x1[300000]; long long x2[300000]; void check(long long xx) { long long ...
CPP
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; long long kadane(const vector<long long> &v) { long long ans = 0; long long curr = 0; for (long long n : v) { curr += n; ans = max(ans, curr); if (curr < 0) curr = 0; } return ans; } int main() { ios_base::sync_with_stdio(false); int n; scanf("%d...
CPP
788_A. Functions again
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 defined as...
2
7
import java.util.*; import java.io.*; public class C1{ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() ...
JAVA
788_A. Functions again
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 defined as...
2
7
n = int(input()) a = [*map(int, input().split())] a = [abs(a[i] - a[i + 1]) for i in range(n - 1)] ans = t1 = t2 = 0 for i in a: t1, t2 = max(t2 + i, 0), max(t1 - i, 0) ans = max(ans, t1, t2) print(ans)
PYTHON3
788_A. Functions again
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 defined as...
2
7
import math def getMax(a, n): MAX = -1*pow(10, 9) memoize = [[0 for x in range(2)] for y in range(n)] difference = [0 for x in range(n)] for i in range(n): if i > 0: difference[i] = abs(a[i]-a[i-1]) for i in range(1, n): memoize[i][0] = max(difference[i], memoize[i-1][1] ...
PYTHON3
788_A. Functions again
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 defined as...
2
7
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; public class Main{ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; ...
JAVA
788_A. Functions again
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 defined as...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; public class Main2 { public static void main(String[] args) { FastScanner scanner = new FastScanner(); int n = scanne...
JAVA
788_A. Functions again
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 defined as...
2
7
n = int(raw_input()) ll = list(map(int, raw_input().split())) l = [abs(ll[i] - ll[i + 1]) for i in xrange(n - 1)] d = [[0, 0] for i in xrange(n - 1)] d[n - 2] = [l[n - 2], l[n - 2]] ans = d[n - 2][1] for i in xrange(n - 3, -1, -1): d[i][0] = l[i] - max(0, d[i + 1][1]) d[i][1] = l[i] - min(0, d[i + 1][0]) if...
PYTHON
788_A. Functions again
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 defined as...
2
7
# In this template you are not required to write code in main import sys inf = float("inf") sys.setrecursionlimit(1000000) #from cmath import sqrt #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace from math import ceil,flo...
PYTHON3
788_A. Functions again
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 defined as...
2
7
n=int(input()) *a,=map(int,input().split()) l=[abs(a[i]-a[i-1]) for i in range(1,n)] ans=0 x=y=0 for i in range(n-1): t=[l[i],-l[i]][i%2] x+=t y-=t ans=max(ans,x,y) x=max(x,0) y=max(y,0) print(ans)
PYTHON3
788_A. Functions again
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 defined as...
2
7
#include <bits/stdc++.h> using namespace std; int n; long long a[110000]; long long b[110000]; long long dp[110000][2]; long long myabs(long long x) { if (x < 0) return -x; else return x; } int main() { while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) scanf("%I64d", &a[i]); for (int i ...
CPP
788_A. Functions again
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 defined as...
2
7
n = int(raw_input()) l = [int(x) for x in raw_input().split()] l1 = [] l2 = [] def best(ll): ans = ll[0] sm = 0 min_sum = 0 for a in ll: sm += a ans = max(ans, sm - min_sum) min_sum = min(min_sum, sm) return ans for i in xrange(n-1): val = abs(l[i+1]-l[i]) if i % 2 == 0: val = -val l1.append(val) ...
PYTHON
788_A. Functions again
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 defined as...
2
7
import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int n = sc.nextInt(); long[] a = sc.nextLongList(n); long[] b = new long[n]; b[0] = a[0]; ...
JAVA