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 long long MAXN = 1e5 + 10;
long long s[MAXN], p[MAXN], a[MAXN];
int32_t main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i];
for (long long i = 1; i + 1 <= n; i++) p[i] = abs(a[i] - a[i + 1]);
for (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.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din... | 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 N = 1e5 + 5;
long long arr[N], odd[N], even[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &arr[i]);
for (int i = 1; i < n; i++) {
odd[i] = abs(arr[i] - arr[i + 1]) * pow(-1, i - 1);
even[i] = odd[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 java.io.*;
import java.math.*;
import java.util.*;
public class C {
final static int MOD = 1000000007;
public static void main(String[] args) throws Exception {
FastReader in = new FastReader(System.in);
int n = in.nextInt();
long[] a = new long[n], D = new long[n - 1];
for (int i = 0; i < n; 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 | #include <bits/stdc++.h>
using namespace std;
const bool print = false;
const int MAXN = 1000111;
long long dp[MAXN][2];
long long t[MAXN];
long long ab(long long x) { return x > 0 ? x : -x; }
int main() {
int n;
scanf("%d", &n);
for (int i = (1); i <= (n); i++) scanf("%lld", &t[i]);
long long wyn = 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 | import java.util.Arrays;
import java.util.Scanner;
public class Three {
public static void main(String[] args) {
// Scanner in = new Scanner("5\n" + "1 4 2 3 1"); //3
// Scanner in = new Scanner("4\n" + "1 5 4 7"); //6
// Scanner in = new Scanner("2\n" + "1 2");
// Scanner in = new Scanner("50\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 | // created by ζδΈη₯ιζζ―θ°
import java.io.*;
import java.util.*;
public class scratch_18{
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input) {
reader = 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 | //package CF;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws Excep... | 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(' ')))
def sign(n):
return [1, -1][n % 2]
b1 = [abs(a[i]-a[i-1]) for i in range(1, len(a))]
b1 = [sign(i)*b1[i] for i in range(len(b1))]
b2 = [-x for x in b1]
max_ending_here = b1[0]
max_so_far = b1[0]
for i, x in enumerate(b1):
if i == 0:
continue
... | 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 N = 1e5 * 2 + 10;
long long dp[N][2], n, a[N], s[N], ans = 0;
int32_t main() {
cin >> n;
for (long long i = (1); i <= (n); ++i) cin >> a[i];
for (long long i = (1); i <= (n - 1); ++i) s[i] = abs(a[i] - a[i + 1]);
for (long long 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 | #include <bits/stdc++.h>
using namespace std;
long long A[100005], diff[100005];
int main() {
int n, i;
long long cur, maxi;
cin >> n;
for (i = 0; i < n; i++) cin >> A[i];
for (i = 0; i < n - 1; i++) {
diff[i] = abs(A[i] - A[i + 1]);
if (i % 2) diff[i] = -diff[i];
}
cur = maxi = diff[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 |
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
public class contest1 {
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int []a=new int[n];
for(int i=0; i<n; i++)
a[i]=scn.nextInt();
ArrayList<Integer> 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 | import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main
{
static int N = 200100;
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())
arr = list(map(int, input().split()))
diff = [abs(arr[i]-arr[i+1]) for i in range(n-1)]
dp = [[0, 0, 0] for _ in range(n-1)]
dp[0][1] = diff[0]
for i in range(1, n-1):
dp[i][0] = max(dp[i-1][0], dp[i-1][1], dp[i-1][2])
dp[i][1] = max(dp[i-1][2]+diff[i], diff[i])
dp[i][2] = dp[i-1][1]-diff[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 | import java.util.*;
public final class Function {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
int n=input.nextInt();
long a=input.nextInt();
long sum=0,min=0,max=0;
long b=0;
for (int i=1;i<n ;i++ ) {
b=input.nextInt();
if (i%2==0) {
sum+=Math.abs(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 | n = int(input())
arr = list(map(int,input().split(' ')))
arr.insert(0,0)
diff_arr = []
end_so_far = 0
max_so_far = 0
l = 1
for i in range(2,len(arr)-1):
temp = abs(arr[i]-arr[i+1])
diff_arr.append(temp*(pow((-1),i)))
end_so_far = end_so_far + diff_arr[-1]
if end_so_far < 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 | import java.util.*;
import java.io.*;
public class Again{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Entrada in = new Entrada(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC s = ne... | 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 n, a[100100];
long long dif[100100], sum1, sum2, maxs;
int main(int argc, char const *argv[]) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
dif[i - 1] = abs(a[i - 1] - a[i]);
}
sum1 = sum2 = 0, maxs = dif[1];
for (int i = 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 | import math
n = int(input())
a= list(map(int,input().split()))
def maxSubArraySum(a):
max_so_far = 0
max_ending_here = 0
for i in range(len(a)):
max_ending_here = max_ending_here + a[i]
if max_ending_here < 0:
max_ending_here = 0
# Do not co... | 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.*;
import java.lang.*;
public class A {
public static long solve(int[] arr) {
long ans = 0;
long maxCurr = 0;
for(int i:arr) {
maxCurr+=i;
if(maxCurr<0) maxCurr = 0;
ans = Math.max(ans, maxCurr);
}
return ans;
}
public static void main(String[] args) {
FastRe... | 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.*;
import java.math.*;
public class code2 {
InputStream is;
PrintWriter out;
void solve()
{
int n=ni();
int a[]=new int[n+1];
for(int i=1;i<=n;i++)
a[i]=ni();
long temp=0,fmax=Long.MIN_VALUE;
for(int i=1;i<n;i++)
{
if(i%2==1)
temp+=Math.abs(a[i+1]-a[i]);
e... | 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.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
// BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=1;
//t=sc.nextInt();
//int t=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 int maxN = 2e5 + 9, MOD = 1e9 + 7;
int n;
long long arr[maxN], ot[maxN];
long long maxsub(long long *arr, int n) {
long long cr = LLONG_MIN / 4, maxi = LLONG_MIN / 4;
for (int i = 0; i < n; i++) {
cr = max(arr[i], cr + arr[i]);
maxi = max(maxi, cr);
}
... | 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[100005];
long long f[100005][2];
long long ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i < n; i++) {
f[i][0] = max(f[i - 1][1] + abs(a[i] - a[i + 1]),
(long long)abs(a[i] - a[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 | #include <bits/stdc++.h>
using namespace std;
long long maxSubArraySum(vector<long long> a) {
long long siz = a.size();
long long max_so_far = a[0];
long long curr_max = a[0];
for (long long i = 1; i < siz; i++) {
curr_max = max(a[i], curr_max + a[i]);
max_so_far = max(max_so_far, curr_max);
}
retur... | 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 Solution
{
public static void main(String ag[])
{
Scanner sc=new Scanner(System.in);
int i,j,k;
int N=sc.nextInt();
int A[]=new int[N+1];
for(i=1;i<=N;i++)
A[i]=sc.nextInt();
int diff[]=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.*;
import java.util.*;
public class A {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
long slow(long[] a) {
long ret = 0;
for (int i = 0; i < a.length; i++) {
long sum = 0;
for (int j = i + 1; j < a.length; j++) {
long diff = a[j] - a[j - 1];
if ((j - 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.util.*;
import java.io.*;
public class FunctAg{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Ta... | 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.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.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 | def f(a):
c, v, m = 0, 0, 1
for i in range(len(a) - 1):
x = m * abs(a[i] - a[i + 1])
c = max(c + x, x)
v = max(v, c)
m *= -1
return v
n, a = int(input()), list(map(int, input().split()))
print(max(f(a), f(a[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;
long long int power(long long int x, long long int y, long long int m) {
if (y == 0) return 1;
long long int p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
long long int nCr(long long int n, long long int r, long long int m) {
... | 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() {
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++) {
dp[i] = v[i];
if (i + 2 >= 3) dp[i] = max(dp[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
def solve():
n = int(input())
a = [int(i) for i in input().split()]
a_dif = [abs(a[i + 1] - a[i]) for i in range(n - 1)]
a1 = [a_dif[i] * (-1)**i for i in range(n - 1)]
md1 = 0
m1 = 0
v = 0
for i in range(n - 1):
v += a1[i]
if v < m1:
m1 = v
... | 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 p[100010];
long long Abs(long long n) {
if (n < 0) return -n;
return n;
}
int main() {
int n, fu = 1;
long long now = 0, Max = 0, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%I64d", &p[i]);
for (int i = 1; i < n; i++) {
if (now ... | 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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class FunctionsAgain
{
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] 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 | n = input()
arr = map(int,raw_input().strip().split(' '))
a = []
for i in range(1,n):
a.append(abs(arr[i] - arr[i-1]))
dpeven = []
dpodd = []
#dpeven
answer = 0
index = 0
while index < n -1 :
if index % 2 == 0:
answer += a[index]
else:
dpeven.append(answer)
if answer >= a[index]:
answer -... | 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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.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 | n=input()
a=map(int,raw_input().split())
d=[]
for i in range(n-1):
x=abs(a[i]-a[i+1])
if i%2==0:
d.append(x)
else:
d.append(-x)
x=0
m=0
for i in range(n-1):
x+=d[i]
if x<0:
x=0
else:
m=max(m,x)
x=0
p=0
for i in range(n-1):
x+=d[i]
if x>0:
x=0
e... | 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>
const int MAX = 100005;
int main() {
long long a[MAX], dp[MAX][2];
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i < n; i++) {
a[i] = abs(a[i] - a[i + 1]);
}
dp[1][1] = a[1];
dp[1][0] = 0;
long long ans = a[1];
for (int 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 | def main():
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]))
max_odd = b[0]
max_even = 0
all_values = [max_odd, max_even]
for bi in b[1:]:
new_odd = max(max_even + bi, bi)
new_even = max(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 | #include <bits/stdc++.h>
using namespace std;
int n;
long long a[100002], f[100002], g[100002], p[100002], q[100002];
int main() {
long long h, fm = 0, gm = 0, pm = 0, qm = 0;
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int(i) = (0); (i) < (n); i++) {
cin >> a[i];
if (i % 2 == 1 and 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 maxs(vector<long long int> a) {
long long int size = a.size();
long long int max_so_far = 0, max_ending_here = 0;
for (long long int i = 0; i < size; i++) {
max_ending_here = max_ending_here + a[i];
if (max_ending_here < 0)
max_ending_here ... | 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())
nums = list(map(int,raw_input().split()))
arr = [0]
arr2 = [0]
for i in range(n-1):
arr.append(abs(nums[i]-nums[i+1]))
arr2.append(abs(nums[i]-nums[i+1]))
for i in range(1,n):
if i%2:
arr[i] *= -1
else:
arr2[i] *= -1
ans = 0
for i in range(n-1):
arr[i+1] += arr[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 n, t, sum1, sum2, ans, a[100001], x, y, b[100001], c[100001];
bool f;
string s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (long long i = 0; i < n; ++i) cin >> a[i];
for (long long i = 0; i < n - 1; ++i) {
t = ... | 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()
arr=map(int,raw_input().strip().split(" "))
diff=[]
for i in range(n-1):
diff.append(abs(arr[i]-arr[i+1]))
ar1,ar2=[],[]
for i in range(len(diff)):
if(i%2==0):
ar1.append(diff[i])
ar2.append(-diff[i])
else:
ar1.append(-diff[i])
ar2.append(diff[i])
m1,maxend,m2=0,0,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 math
maxi = (10 ** 5) + 5
Xb = [0 for i in range(maxi)]
Xc = [0 for i in range(maxi)]
n = input()
lista = map(int, raw_input().split())
A = [0 for i in range(n+1)]
for i in range(1, n+1):
A[i] = lista[i-1]
a = [0 for i in range(n+1)]
for i in range(1, n):
a[i] = abs(A[i]-A[i+1])
Xc[1] = a[1]
Xb[1] = 0
mirespu... | 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.*;
import java.io.*;
public class a
{
public static void main(String[] arg) throws IOException
{
new a();
}
long[][] memo;
long oo = Long.MIN_VALUE/10;
int n;
long[] vs;
public a() throws IOException
{
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System... | 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.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 | import java.util.*;
import java.util.stream.*;
import java.io.*;
import java.math.*;
public class Main {
static boolean FROM_FILE = false;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
if (FROM_FILE) {
t... | 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 maxSubArraySum(long long a[], long long size) {
long long max_so_far = 0, max_ending_here = 0;
for (long long i = 0; i < size; i++) {
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here) max_so_far = max_ending_here;
if (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 | 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 | from sys import stdin
from math import fabs, copysign
a = map(int, stdin.read().split())
n = a[0]; a = a[1:]
b = list()
for i in range(1, n):
a[i - 1] = int(copysign(a[i] - a[i - 1], ((i & 1) << 1)- 1))
a[n - 1] = 0
ans, tmp, l, r = a[0], a[0], 0, 0
while r < n - 1:
r += 1
tmp += a[r]
while tmp < 0 and l <= r:
t... | 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 double pi = 3.1415926535;
const int MI = 2147483647;
const int mod = 1e9 + 7;
const int Max = 2e5 + 25;
long long a[Max];
long long dp[Max][2];
int main() {
cin.sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
long long 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long i, n;
cin >> n;
long long a[n], b[n - 1], c[n - 1];
for (i = 0; i < n; i++) {
cin >> a[i];
if (i > 0) {
if (i % 2 != 0) {
b[i - 1] = abs(a[i] - a[i - 1]);
c[i - 1] = -b[i - 1];
} else {
b[i - 1] = -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 A[500005];
int main() {
int n, a;
scanf("%d", &n);
for (int i = 1; i < n + 1; i++) {
scanf("%d", &A[i]);
}
priority_queue<long long> pq1;
priority_queue<long long> pq2;
long long sum1 = 0;
long long sum2 = 0;
for (int i = 1; i < n; i++) {
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 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
long long dp1[N], dp2[N];
int main() {
int n;
scanf("%d", &n);
long long a[n];
for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
dp1[n - 1] = dp1[n - 1] = a[n - 1];
for (int i = n - 2; i >= 0; i--) dp1[i] = abs(a[i] - a[i + 1]);
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() {
int n, input[100000];
long long int a = 0, b = 0, maxnum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> input[i];
if (i > 0) {
if (i % 2 == 1) {
a = max(a + abs(input[i - 1] - input[i]), (long long int)0);
b = max(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 | import java.io.*;
import java.util.*;
public class A{
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.nextInt();
}
int cum[] = new int[n-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.util.*;
import java.io.*;
public class A
{
public static void main(String[] args) throws Exception
{
PrintWriter out = new PrintWriter(System.out);
new A(new FastScanner(System.in), out);
out.close();
}
public A(FastScanner in, PrintWriter out)
{
int N = 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.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 po(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) {
res = (res * a) % 1000000007;
}
a = (a * a) % 1000000007;
b = b / 2;
}
return res % 1000000007;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie... | 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.*;
import java.math.*;
public class cb {
InputStream is;
PrintWriter out;
static long mod=(long)(1e7+9);
static long mx=Integer.MIN_VALUE;
static long maxSubArraySum(long a[])
{
int size = a.length;
long max_so_far = Integer.MIN_VALUE, max_ending... | 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() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
long long int* arr = new long long int[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long mx = 0, mn = 0, res = 0, a, s = 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 java.io.*;
import java.util.*;
public class C
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = Integer.parseInt(br.read... | 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.StringTokenizer;
public class Main {
static int INF = (int) 2e9;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int[] 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 | /*
* Author- Priyam Vora
* BTech 2nd Year DAIICT
*/
import java.awt.Point;
import java.io.*;
import java.math.*;
import java.util.*;
import javax.print.attribute.SetOfIntegerSyntax;
... | 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.math.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class codeforces implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
... | 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 again
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String s[]=br.readLine().trim().split(" ");
int 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 | #include <bits/stdc++.h>
using namespace std;
long long ar1[100000 + 200], ar2[100000 + 200], ar3[100000 + 200];
int main() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> ar1[i];
for (long long i = 1; i < n; i++) {
if (i % 2 == 1) {
ar2[i] = abs(ar1[i] - ar1[i + 1]);
ar3[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 = 2e5 + 5;
long long int a[N], diff[N], n, cache[N][2];
long long int dp(long long int i, long long int sign) {
if (i >= n) {
return 0;
}
long long int &ans = cache[i][sign];
if (ans != -1) {
return ans;
}
ans = diff[i];
if (sign == 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 power(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long int binomial(long long int n, long long int k) {
long long int C[k + 1];
memset(C, 0, sizeof(C));
... | 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
import inspect
import re
import math
from collections import defaultdict
from pprint import pprint as pi
MOD = 10e9 + 7 #998244353
INF = 10**12
n = int(input())
a = list(map(int,input().split()))
d = []
for i in range(1,n):
d.append(abs(a[i]-a[i-1]))
n-=1
sum=0
cur=0
for i in range(n):
cur += (((i+1)%2) - ... | 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, x[600000], y[600000], best, tmp, mins, idx;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> y[i], x[i - 1] = abs(y[i - 1] - y[i]);
best = 0, idx = 1;
while (idx <= N - 1) {
tmp = x[idx];
best = max(best, tmp);
mins = 1;
while ... | 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 binpow(long long base, long long exp, int mod) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
long long mod(long long x) {
return ((x % 1000000007... | 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 maxSubArraySum(vector<long long> a) {
long long size = a.size();
if (size == 0) return -1000000000;
long long max_so_far = a[0];
long long curr_max = a[0];
for (long long i = 1; i < size; i++) {
curr_max = max(a[i], curr_max + a[i]);
max_so_far =... | 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()))
ls=[abs(arr[i+1]-arr[i])*(-1)**(i%2) for i in range(n-1)]
ls1=[abs(arr[i+1]-arr[i])*(-1)**(1-i%2) for i in range(n-1)]
su=0
s=0
for i in ls:
su+=i
if su<0:
su=0
else:
s=max(s,su)
su=0
for j in ls1:
su+=j
if su<0:
su=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;
long long p[100005], x[100005];
long long dp[100005];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= n - 1; i++) {
x[i] = abs(p[i] - p[i + 1]);
if (i % 2 == 0) x[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 java.util.Scanner;
public class P5 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int a[] = new int[n - 1];
int l = scan.nextInt();
for (int i = 0; i < n - 1; i++) {
int r = 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 | # n, m = [int(x) for x in input().split(" ")]
# s = set()
# ls = [0]*(n+1)
# in_C = input().split(" ")
#
# for x in range(len(in_C)-1, -1, -1):
# s.add(int(in_C[x]))
# ls[x+1] = len(s)
# [print(ls[int(input())]) for i in range(m)]
#
# in_x = input()
# n = list(in_x)
# length = len(n)
# counter = 0
# counter_2 =... | 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 FunctionsAgain {
//static long[][] dp ;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n = input.nextInt()-1;
int[] aa = new int[n];
int a = input.nextInt();
for(int i=0;i<n;i++){
int ... | 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 n;
vector<long long> data;
long long a;
int main() {
cin >> n;
long long nn = 0;
for (int i = 0; i < n; i++) {
cin >> a;
data.push_back(a);
}
long long answer = -1;
long long now = 0;
long long mm = 0;
for (int i = 0; i < n - 1; i++) {
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 | #include <bits/stdc++.h>
using namespace std;
long long int abso(long long int a) { return (a < 0) ? a * -1 : a; }
int main() {
int n;
long long int a[100001], ans = 0, maxi = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
if (i % 2) {
ans += abso(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 | n = int(input())
f = []
arr = list(map(int, input().split()))
for i in range(0, len(arr) - 1):
f.append(abs(arr[i] - arr[i + 1]))
dp = [[0] * len(f), [0] * len(f)]
dp[0][0] = 0
dp[1][0] = f[0]
for i in range(1, len(f)):
dp[0][i] = dp[1][i-1]-f[i]
dp[1][i] = max(dp[0][i - 1] + f[i], f[i])
ans = max(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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Inte... | 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 M = 1e5 + 10;
int n;
long long a[M];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%I64d", a + i);
}
for (int i = 1; i < n; ++i) {
a[i] = abs(a[i + 1] - a[i]);
if (i & 1) a[i] = -a[i];
}
long long ans = -1e17;
long 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;
int main() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long b[n + 1], c[n + 1];
b[0] = 0;
c[0] = 0;
long long sum = -1e15, sum1 = -1e15, mb = 0, mc = 0;
for (long long i = 0; i < n - 1; i++) {
b[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 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
using ll = long long;
ll a[maxn];
ll b[maxn];
ll c[maxn];
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i < n; ++i) {
a[i] = abs(a[i] - a[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 java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* Created by Rakshit on 8/4/17.
* Java is Love.. :)
*/
public class FuncAg {
static int n;
stat... | 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;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> v(n);
deque<ll> a(n + 10);
for (int i = 0; i < n; ++i) cin >> v[i];
for (int i = 1; i < n; ++i) a[i] = abs(v[i - 1] - v[i]);
a.pop_front();
ll re... | 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 int N = 200010;
const long long mod = 1000000007;
const long long inf = 1000000000000000000;
const long double pi = 3.14159265358979323846264338;
long long int kadane_algo(vector<long long int> a) {
long long int ans = a[0], curr = a[0];
for (long long 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
import math,bisect,operator
inf,mod = float('inf'),10**9+7
# sys.setrecursionlimit(10 ** 6)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = la... | 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 num[100005];
int main() {
long long n, mx = 0, mn = 0, sum = 0;
scanf("%lld %lld", &n, &num[1]);
for (long long i = 2; i <= n; i++) {
scanf("%lld", &num[i]);
if (i % 2)
sum += abs(num[i] - num[i - 1]);
else
sum -= abs(num[i] - num[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(input())
a=list(map(int,input().split()))
dp=[[0,0] for i in range(n)]
dp[0][1]=abs(a[1]-a[0])
maxi=abs(a[1]-a[0])
for i in range(1,n-1):
dp[i][0]=max(0,dp[i-1][1]-abs(a[i]-a[i+1]))
dp[i][1]=max(0,dp[i-1][0]+abs(a[i]-a[i+1]))
maxi=max(maxi,dp[i][0],dp[i][1])
print(maxi) | 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 sys import stdin
inf = float("inf")
N, = map(int, stdin.readline().split())
A = list(map(int, stdin.readline().split()))
diffodd = [0] * (N)
diffeven = [0] * (N)
for i in range(1, N):
v = abs(A[i - 1] - A[i])
if i % 2 == 1:
diffodd[i] = v
diffeven[i] = -v
else:
diffeven[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 | import java.io.*;
import java.util.*;
public class cf407c {
static final int N=(int)1e5+10;
static final long inf=(long)1e10;
static int a[]=new int[N];
static long b[]=new long[N];
static long c[]=new long[N];
public static void main(String[] args){
Scanner cin=new Scanner(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;
int main() {
int n;
cin >> n;
vector<long long int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
long long int sum = abs(v[0] - v[1]), ma = abs(v[0] - v[1]);
for (int i = 2; i < n; i++) {
if (i % 2 == 0) {
sum -= abs(v[i] - v[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 | #include <bits/stdc++.h>
using namespace std;
long long go(vector<long long> a) {
long long result = 0;
long long now = 0;
for (auto& item : a) {
now += item;
if (now < 0) {
now = 0;
}
result = max(result, now);
}
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin.ti... | 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.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
public class P788A
{
public static void main(String[] args)
{
FastScanner in = new FastScanner(System.in);
int n = in.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
long[... | 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 cf407c {
static final int N=(int)1e5+10;
static final long inf=(long)1e10;
static int a[]=new int[N];
static int b[]=new int[N];
static int c[]=new int[N];
public static void main(String[] args){
Scanner cin=new Scanner(new Inpu... | 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;
using std::cin;
using std::cout;
long long MOD = 998244353;
int main() {
int n;
cin >> n;
int tmp[n];
long long arr[n - 1];
for (int i = 0; i < n; i++) cin >> tmp[i];
for (int i = 0; i < n - 1; i++) {
arr[i] = abs(tmp[i + 1] - tmp[i]);
}
long long maxn =... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.