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> using namespace std; const int maxn = 1e5 + 4; long long int a[maxn], dif1[maxn], dif2[maxn]; long long int kadane(long long int arr[], int n) { long long int ans = -2e9, curr_max = -2e9; for (int i = 1; i < n; i++) { curr_max = max(arr[i], curr_max + arr[i]); ans = max(curr_max, an...
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; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); solve(); return 0; } long long maxA = LONG_MIN, max_ending_here = 0, maxB = LONG_MIN, sumA = 0, sumB = 0; bool A = 0, B = 0; void solve() { int n; cin >> n; ve...
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 n, res, a[1 << 17], S[1 << 17], mx, mi; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%lld", a + i); for (int i = 1; i < n; i++) { S[i] = S[i - 1] + abs(a[i] - a[i + 1]) * (i & 1 ? 1 : -1); res = max(res, max(mx - S[i], S[i] - mi)), ...
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_base ::sync_with_stdio(0); long long int n, k; cin >> n; long long int a[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int mx1 = -1e9, mx2 = -1e9, c1 = 0, c2 = 0; for (int i = 0; i < n - 1; i++) { long long int aux =...
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 ProblemC { static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writ...
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 i; long long a[100005]; long long b[100005]; int main() { int n; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i < n; i++) { b[i] = llabs(a[i] - a[i + 1]); } long long bestSum = -200000000000000000LL, sum = 0, sum2 = 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
n = int(input()) a = list(map(int, input().split())) aux = 0 minaux = 0 maxim = 0 results = [] for i in range(1, n): results.append(abs(a[i-1] - a[i])) for i in range(0,n-1): if i%2 == 1: condition = -results[i] else: condition = results[i] aux += condition minaux -= condition ...
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 = 2e5 + 5; const int MOD = 1e9 + 7; long long dp[N][2][2]; int arr[N]; int n; long long solve(int idx, bool take, int sign) { if (idx == n) return 0; long long& cur = dp[idx][take][sign + 1]; if (cur != -1) return cur; if (take) { return cur = max(0l...
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 v[100005], dp[100005], Max; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i <= n - 1; i++) v[i] = abs(v[i] - v[i + 1]); n--; for (int i = 1; i <= n; 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.Scanner; public class App { public static void main(String[] args) { Scanner inp = new Scanner(System.in); int n = inp.nextInt(); int[] arr = new int[n + 1]; for (int i = 1; i <= n; i++) { arr[i] = inp.nextInt(); } for (int i = 1; i < n; i++) { arr[i] -= arr[i + 1]; arr[i] = Mat...
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 mod = 1e9 + 7; const long long INF = 0x7FFFFFFFFFFFFFFF / 2; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long arr[n]; vector<long long> pos, neg; for (int i = 0; i < n; i++) { cin >> arr[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> using namespace std; using ld = long double; int t[102], low[102], high[102]; using ull = unsigned long long; int mod = pow(10, 9) + 7; long long int arr[200009], val[200009], ans[200009]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i < n; 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.*; import java.io.*; public class Daniel { public static void main (String[] args) { Scanner dank = new Scanner(System.in); int n = dank.nextInt(); int [] a = new int [n]; int [] b = new int [n-1]; for(int d = 0; d<n; d++) { a[d] = dank.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.*; import java.util.*; public class A { public static void solution(BufferedReader reader, PrintWriter writer) throws IOException { In in = new In(reader); Out out = new Out(writer); int n = in.nextInt(); int[] a = in.nextIntArray(n); long[] even =...
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 a[100 * 1000]; int b[100 * 1000]; int main() { ios::sync_with_stdio(false); int n; long long max = (-1) * 1e15, maxn, maxp; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; maxn = maxp = abs(a[n - 2] - a[n - 1]); for (int i = n - 2; i >= 0; i--) { lo...
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; const int INF = 0x3f3f3f3f; const double eps = 1e-8; inline int read() { int ans = 0, flag = 1; char c; c = getchar(); while (c < '0' || c > '9') { if (c == '-') flag = -1; c = getchar(); } while (c >= '0' && c <= '9') { ans...
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 OO = (int)2e9 + 5; const int MOD = (int)1e9 + 7; const long double Pi = 3.141592653589793238; const int N = (int)2e5 + 5; long long qqaGJJ[N], ss[2][N], vRI[2][N], n, uVyh = 0; int main() { cin >> n; for (int i = (int)(1); i <= (int)(n); i++) cin >> qqaGJJ[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 sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\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> using namespace std; const int MAX_N = 100000; const int MAX_E2 = 1 << 18; const long long LINF = 1LL << 62; template <typename T, const int MAX_E2> struct SegTreeMinMax { int e2; T mins[MAX_E2], maxs[MAX_E2], inf; SegTreeMinMax() {} void init(int n, T inf) { for (e2 = 1; e2 < n; e2...
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
//package Round_407; import java.util.Scanner; public class C { private void println(Object obj) { System.out.println(obj); } public C() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] a = new long[n]; long[] b = new long[n - 1]; long[] c = new long[n - 1]; a[0] = sc.nextLong();...
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 n, arr[100005], dif[100005]; long long tot, tot2; int main() { long long ans = 0; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i < n; i++) { dif[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.*; import java.lang.Math; public class Functions { public long fun(int n, long[] array) { long[] newarray = new long[n - 1]; for (int i = 0; i < n - 1; i++) { newarray[i] = Math.abs(array[i] - array[i + 1]); } long sum = 0; ...
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 math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) def list...
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() { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long int f[n - 1]; for (int i = 0; i < n - 1; i++) f[i] = (i % 2) ? abs(a[i + 1] - a[i]) : -abs(a[i + 1] - a[i]); long long int sum = 0, mx = -1e9; 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
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int a[100005]; long long dp1[100005], dp2[100005]; int a1[100005], a2[100005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) { if (i % 2) { a1[i] = abs(a[i] - 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; int n, b[100004], c[100004], a[100003]; long long res1, res2, sum1, sum2; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { if (i & 1) b[i] = abs(a[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.*; import java.lang.*; public class fagain { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = sc.nextInt(); } long[] a = new long[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
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 1e9 + 7; const int N = 2e5 + 7; const int M = 1e6 + 7; long long a[N], b[N]; long long dp[N][2]; signed main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i > 1) 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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; 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
import java.io.*; import java.util.*; public class div407C { BufferedReader in; PrintWriter ob; StringTokenizer st; public static void main(String[] args) throws IOException { new div407C().run(); } void run() throws IOException { //in=new BufferedReader(new FileReader("input.txt")); in=new BufferedReader(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.util.Scanner; public class FunctionsAgain { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] arr = new int[n]; long[] evensum = new long[n-1]; long[] oddsum = new long[n-1]; for(int i = 0; i < n; i++){ arr[i] = scan.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
#include <bits/stdc++.h> inline long long llabs(long long x) { return x < 0 ? -x : x; } long long b[100000], m = 0; int n; void dp() { long long sum = 0; for (int i = 0; i < n; i++) { sum += b[i]; if (sum < 0) { sum = 0; continue; } if (b[i] > 0) m = m > sum ? m : sum; } } int main() {...
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
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main{ public static int f(int[] a,int l,int r){ int sum = 0; for(int i = l;i<r;i++){ int num = Math.abs(a[i] - a[i + 1]) * ((i - l)...
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.util.Scanner; import java.util.StringTokenizer; public class c { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] arr...
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())) arr=[abs(a[i]-a[i+1])*(-1)**i for i in range(n-1)] maximum=0 summ=0 for j in arr: if j>0 or abs(j)<abs(summ): summ+=j else: summ=0 maximum=max(maximum, abs(summ)) summ=0 for k in arr[1:]: if k<0 or abs(k)<abs(summ): summ+=k els...
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 n, a1, a2, c, b, t, y, d; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a1; while (--n) { cin >> a2; b = abs(a1 - a2); a1 = a2; t = c; c = max(b, d + b); y = max(y, c); d = t - b; } cout << y; ...
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 N = 1e5 + 10; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fLL; long long a[N], b[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long ans = -INF, sum = 0; cin >> n; 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
#include <bits/stdc++.h> using namespace std; int main() { long long i, n; cin >> n; long long a[100005], alpha[100005], bravo[100005]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); for (i = 0; i < n - 1; i++) { if (i == 0 || i % 2 == 0) { alpha[i] = abs(a[i] - a[i + 1]); bravo[i] = -1 * abs(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
from sys import stdin n = int(stdin.readline()) def sub(a): ans = 0 cur = 0 for i in a: cur += i if cur < 0: cur = i if cur < 0: cur = 0 ans = max(ans,cur) return ans a = map(int,stdin.readline().split()) b = [] c = [] for i in xrange(n-1): x = a[i] - a[i+1] if x < 0: x = -x if i%2: b.append(x)...
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
//package com.company; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws IOException { // write your code here Scanner s = new Scanner(System.in); // BufferedRead...
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_subarray(A): max_ending_here = max_so_far = A[0] for x in A[1:]: max_ending_here = max(x, max_ending_here + x) max_so_far = max(max_so_far, max_ending_here) return max_so_far n = int(input()) a = [int(v) for v in input().split()] b = [abs(a[i]-a[i+1])*(-1)**i for i in range(n-1)] p...
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()) num = list(map(int, input().split())) diff = [abs(j-i) for i, j in zip(num, num[1:])] s1 = 0 s2 = 0 m1 = 0 m2 = 0 for i, x in enumerate(diff): if s1 < 0: s1 = 0 if s2 < 0: s2 = 0 if i % 2 == 0: s1 += x s2 -= x else: s1 -= x s2 += x ...
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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class C_407 { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); int n = Integer.parseInt(input.readLine()); int[] nums = 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
import java.util.Scanner; public class FunctionsAgain { public static void main(String[] args) { try (Scanner s = new Scanner(System.in)) { int n = s.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = s.nextInt(); } // Store the best negative and positive function value star...
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.lang.*; import java.io.*; import java.math.*; import java.text.*; public class Prac{ static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(Input...
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 max_n = 200005; long long b, a, dp1[max_n], dp2[max_n]; int n; int main() { cin >> n; cin >> a; int f = 1; for (int i = 1; i < n; ++i) { cin >> b; dp1[i - 1] = abs(a - b) * f; dp2[i - 1] = abs(a - b) * (-f); f = -f; a = b; } long lo...
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.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author wannabe */ public class Main { public static void main(String[] args) { InputStream 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
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.ObjectInputStream.GetField; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.u...
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 main(): input() aa = list(map(int, input().split())) a, s = aa[0], 1 u = c = mi = ma = 0 for b in aa: c += abs(a - b) * s a = b s *= -1 if ma < c: ma = c u = ma - mi elif mi > c: mi = c a, s = aa[0], -1 v = c = 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
from math import inf n=int(input()) a=list(map(int,input().split())) b=[] for i in range(len(a)-1): b.append(abs(a[i]-a[i+1])) mini=-inf dp=[[0 for i in range(2)]for j in range(len(b))] dp[0][0]=b[0] dp[0][1]=0 for i in range(1,len(b)): dp[i][0]=max(dp[i-1][1]+b[i],b[i]) dp[i][1]=dp[i-1][0]-b[i] ##print(b) ...
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 a[100004]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; long long count = 0, m = abs(a[1] - a[2]); int s = 1; for (int i = 1; i <= n - 1; i++) { count += abs(a[i] - a[i + 1]) * s; s *= -1; m = max(m, count); 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> using namespace std; inline int read() { int s = 0, t = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') t = -1; c = getchar(); } while (isdigit(c)) s = s * 10 + c - 48, c = getchar(); return s * t; } const int N = 1e5 + 5; const long long inf = 1e16; long long f[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; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <typename Args> void kill(Args args) { cout << args << "\n"; exit(0); } const double PI = acos(-1); const long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LLIN...
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 b[100005]; long long c[100005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]); for (int i = 1; i < n; i++) { b[i] = a[i + 1] - a[i]; if (b[i] < 0) b[i] = -b[i]; } c[0] = 0ll; 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
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int i, j, k, t, c, n; cin >> n; int a[n]; int b[n]; for (i = 0; i < n; i++) cin >> a[i]; ; for (i = 0; i < n - 1; i++) { b[i] = abs(a[i] - a[i + 1]); } long long ans = 0; long long sum = 0; 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
from sys import stdin,stdout # stdin = open("input.txt" , "r") # stdout = open("output.txt", "w") n = int(stdin.readline().strip()) arr = list(map(int,stdin.readline().strip().split(' '))) tarr1 = [abs(arr[1]-arr[0])] tarr2 = [] for i in range(2,n): tarr1.append(pow(-1,i-1)*abs(arr[i]-arr[i-1])) tarr2.append(-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; const long long LLINF = LLONG_MAX; const int INF = INT_MAX; const int MAXN = 1e5 + 10; int n; long long a[MAXN]; long long b[MAXN], c[MAXN]; long long F(long long* a) { long long ret = -LLINF, curr = 0; for (int i = 0; i < n - 1; i++) { curr += a[i]; if (curr > ...
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 def read_ints(): return [int(x) for x in sys.stdin.readline().strip().split()] def main(): N = read_ints()[0] a = read_ints() nums = [abs(a[i] - a[i + 1]) for i in range(N - 1)] N -= 1 odd = [0] * N even = [0] * N odd[0] = nums[0] for ix in range(1, N): odd[ix...
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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamRead...
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> const long long mod = 1000 * 1000 * 1000 + 7; const long long mod1 = 998244353; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (long long)(res *...
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 inp(): return int(raw_input().strip()) def inp_s(): return raw_input().strip() def inp_arr(): return map(long, raw_input().strip().split()) 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...
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; long long int kadanes(long long int* arr, long long int n) { long long int max_so_far = arr[0], sum = arr[0]; for (long long int i = 1; i < n; i++) { sum = max(sum + arr[i], arr[i]); max_so_far = max(max_so_far, sum); } return max_so_far; } void solve() { ...
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
# target Expert # Author : raj1307 - Raj Singh # Date : 25.07.19 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): re...
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.util.Scanner; /** * * @author Hodaifa A Quraini */ public class JavaApplication76 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.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
def m(q): s=0 an=0 for i in range(len(q)): s+=q[i] if s<0: s-=q[i] an=max(s,an) s=0 an=max(s,an) an = max(s,an) return an n= int(input()) a=[int(x) for x in input().split()] z=[] y=[] p=-1 for i in range(0,n-1): p*=-1 z.append(p*a...
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.util.*; import java.io.*; import java.math.*; public class Fuck{ static long MOD=(long)Math.pow(10,9)+7; static final int lint=Integer.MAX_VALUE; static final double ldouble=Double.MAX_VALUE; public static void main(String args[]) { new Thread(null, new Runnable() { public void run()...
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 MOD = 1000000007; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int INF = 0x3f3f3f3f; const int N = 1e5 + 5; long long a[N], b[N], c[N], d[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> 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
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], b[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", a + i); for (int i = 1; i < n; ++i) b[i] = abs(a[i] - a[i + 1]); for (int i = 1; i < n; ++i) { if (i & 1) b[i] = -b[i]; } long long ans = 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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int* arr = new int[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int* dp1 = new int[n]; for (int i = 1; i < n; i++) dp1[i] = abs(arr[i - 1] - arr[i]); long long* dp2 = new long long[n]; dp2[0] = 0; for (int i = 1; i < n; 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 sys if __name__=='__main__': n = int(sys.stdin.readline()) A = [int(x) for x in sys.stdin.readline().split()] B = [ abs( A[i]-A[i+1] ) for i in range(n-1) ] C, m = [B[0]], -1 for i in range(1, n-1): C.append(C[i-1] + m*B[i]) m*=-1 #print(C) print( max( max(C), max(C)-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; long long A[100001]; long long S1[100001]; long long S1_suff_max[100001]; long long S2[100001]; long long S2_suff_max[100001]; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 2; i <= 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
n=input() lst=map(int,raw_input().split()) 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 lst2=[] for i in range(0,n-1): vr=abs(ls...
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.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 */ public class Main { public static...
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())) d = list(map(lambda i: abs(a[i] - a[i + 1]), range(n - 1))) x = list(map(lambda i: d[i] * (-1) ** i, range(0, n - 1))) y = list(map(lambda i: d[i] * (-1) ** (i + 1), range(0, n - 1))) max1 = x[0] s = 0 for l in range(0, n - 1, 1): s += x[l] max1 = max([max1...
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.util.Scanner; public class C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] ar = new int[n]; for(int i = 0; i < n; i++) { ar[i] = sc.nextInt(); } sc.close(); int[] pslre = new int[n-1]; int[] ptlanlre = ...
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 math input() seq = [0] + [ int(i) for i in input().split() ] cum = [0] + [ abs(seq[i - 1] - seq[i]) if i > 1 else 0 for i in range(1, len(seq)) ] mx = -math.inf eve = [0] * len(cum) odd = [0] * len(cum) for i in range(2, len(cum)): eve[i] = max( cum[i], odd[i - 1] + cum[i]) odd[i] = max(-cum[i], eve[...
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; void solve() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long d[n - 1]; for (long long i = 1; i < n; i++) { d[i - 1] = abs(a[i] - a[i - 1]); } long long sum = 0, ans = LONG_MIN; for (long long 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
#include <bits/stdc++.h> volatile bool isLocalTestEnabled = 0; bool g_isLocalPrintEnabled = (bool)(0); template <typename T> void UpdateMin(T& a, const T b) { a = std::min(a, b); } template <typename T> void UpdateMax(T& a, const T b) { a = std::max(a, b); } const long double Pi = std::atan(1.0L) * 4.0L; static con...
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 A { static boolean tests = false; static void solve(){ int n = fs.nextInt(); long[] a = fs.readLongArray(n); long[] diff = new long[n]; for (int i = 0; i+1 < n; ++i){ diff[i] = Math.abs(a[i]-a[i+1]); ...
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 math n = int(input()) seq = [0] + list(map(int, input().split())) cum = [0] + list(abs(seq[i-1] - seq[i]) if i > 1 else 0 for i in range(1, n+1)) mx = -math.inf eve = [0]*len(cum) odd = [0]*len(cum) for i in range(2, len(cum)): eve[i] = max(cum[i], odd[i-1] + cum[i]) odd[i] = max(-cum[i], eve[i-1] - cum[...
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.util.Arrays; import java.util.Scanner; public class Prob3 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] a = new long[n-1]; long last = in.nextLong(); for (int i = 1; i < n; i++) { long current = in.nextLong(); a[i-1] = Math....
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
# coding=utf-8 import sys import math import random # sys.stdin = open("a.in", "r") def __main__(): n = int(input()) d = [int(e) for e in input().split()] f = [abs(d[i+1] - d[i]) for i in range(n-1)] a = f[0] b = 0 ans = a for i in range(1, len(f)): if (i % 2 == 1): a = a - f[i] b = max(b + f[i], f[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
n = int(input()) a = list(map(int, input().split())) b = [] for i in range(1, n): b.append(abs(a[i] - a[i-1])) n = len(b) for i in range(n): b[i] *= (-1) ** (i % 2) ans = 0 mx = 0 mi = 0 s = 0 for i in range(n): s += b[i] ans = max(ans, max(abs(s-mx), abs(s-mi))) mx = max(s, mx) mi = min(s, mi) ...
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() { long long int m1, m2, s, n, arr[100003], brr[100003]; scanf("%lld", &n); for (int i = 0; i < n; ++i) scanf("%lld", &arr[i]); for (int i = 0; i < n - 1; ++i) { brr[i] = abs(arr[i] - arr[i + 1]); if (i % 2) brr[i] *= -1; } m1 = -1000000000; ...
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.ArrayList; import java.util.Collections; import java.util.Scanner; public class Code { public static void main(String[] args) { // Use the Scanner class Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] A = new int[n]; for (int i = 0; i < 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
from sys import stdin n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) if n==2: print(abs(a[0]-a[1])) exit() mx_cur1,mx_glob1=abs(a[0]-a[1]),abs(a[0]-a[1]) for i in range(1,n-1): tmp=abs(a[i]-a[i+1])*(-1)**i mx_cur1=max(mx_cur1+tmp,tmp) mx_glob1=max(mx_cur1,mx_glob1) mx_cur2,mx_glob...
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.util.*; public class Codeforces { private static void sport(int[] a) { int n = a.length; int[] b = new int[n-1]; for (int i = 0; i < n-1; i++) { b[i]=Math.abs(a[i]-a[i+1]); } //-3 2 -1 2 System.out.println(Math.max(max(b,0),max(b,1))); } ...
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper p...
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 a[100005]; int b[100005], n; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) b[i] = abs(a[i] - a[i + 1]); long long s = b[1], s1 = b[1]; int l = 1; for (int i = 2; i < n; i++) { while (s <= 0 && i - 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
n=int(input()) a=list(map(int,input().split())) b=[abs(a[i]-a[i+1]) for i in range(n-1)] for i in range(0,n-1,2): b[i]*=-1 dp=[0]*(n-1) dp[0]=b[0] for i in range(1,n-1): dp[i]=max(dp[i-1]+b[i],b[i]) ans=max(dp) for i in range(n-1): b[i]*=-1 dp=[0]*(n-1) dp[0]=b[0] for i in range(1,n-1): dp[i]=max(dp[i-1]+b[i],b...
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.util.*; import java.io.*; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int n = in.nextInt(); int[]a= new int[n]; for (int i =0;i<n;i++) a[...
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 Functions_Again { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = ...
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[100005], f[100005], d[100005]; int main() { long long n; cin >> n; f[0] = 0; for (long long i = 0; i < n; i++) { cin >> A[i]; if (i) { d[i - 1] = abs(A[i] - A[i - 1]); if (i % 2) f[i] = f[i - 1] + d[i - 1]; else ...
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.io.PrintStream; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public cl...
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=input().split() arr=[abs(int(a[i])-int(a[i+1]))*(-1)**i for i in range(n-1)] maximum=0 summ=0 for j in arr: if j>0 or abs(j)<abs(summ): summ+=j else: summ=0 maximum=max(maximum, abs(summ)) summ=0 for k in arr[1:]: if k<0 or abs(k)<abs(summ): summ+=k else: ...
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 n, ans, ans2, sum, a[500000], d1[500000], d2[500000]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { d1[i + 1] = abs(a[i] - a[i + 1]); if (i % 2 == 0) d1[i + 1] *= -1ll; d2[i + 1] = abs(a[i] - a[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> using namespace std; long long int a[100005], dp[100005][2], dpsol[100005]; void init() { memset(dp, -1, sizeof(dp)); memset(dpsol, -1, sizeof(dpsol)); return; } void maxm(long long int st, long long int en) { for (long long int i = en; i >= st; i--) { if (i == en) { dp[i][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
import sun.misc.resources.Messages_pt_BR; import javax.print.attribute.standard.MediaPrintableArea; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.*; /** * Created by FirΠ΅fly on 1/1/2017. */ public class Task { public static void 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
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; inline long long getint() { long long _x = 0, _tmp = 1; char _tc = getchar(); while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar(); if (_tc == '-') _tc = getchar(), _tmp = -1; while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_...
CPP