Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a_sum(n); long long a; long long kiyu = 0; long long sum_m = 0; long long sum_p = 0; long long ans_m = 0; long long ans_p = 0; for (long long i = 0; i < n; i++) { cin >> a; kiyu += a; a_su...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } int sum = a.at(0); bool p = false; bool n = false; int num = 0; if (a.at(0) > 0) { p = true; for (int i = 1; i < N; i++) { sum += a.at(i); ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <iostream> #include <vector> #include <string> #include <cstring> #include <math.h> #include <limits.h> #include <map> #include <algorithm> #include <functional> using namespace std; int main() { int n; vector<long long> A; int j; bool is_plus; long long ans = 0; long lo...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; constexpr long long MOD = 1e9 + 7; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; long long A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; long long ans = 0; template <typename T> istream &operator>>(istream &is, vec...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int d[n]; for(int i=0;i<n;i++) { cin >> d[i]; } int count=0; int sum=d[0]; int f =0; if(d[0]>0){ f=-1; } if(d[0]<0){ f=1; } for(int i=1;i<n;i++){ sum+=d[i]; if(sum>0){ if(f==1){ f=-1; continue; } if(f==-1){ count...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int a[n]; long long int s = 0; long long int ans = INT_MAX; int i; for (i = 0; i < n; i++) cin >> a[i]; s = a[0]; long long int p = 0; if (s > 0) { f...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
if(a[0]==0){ ans1++; sum0=1; }else{ sum0=a[0]; } REP(i,1,n){ sum1=sum0+a[i]; if(sum1*sum0<0){ }else if(sum1*sum0>0){ ans1+=abs(sum1)+1; sum1=-1*sum0/abs(sum0); }else{ ans1++; sum1=-1*sum0/abs(sum0); } sum0=sum1; }
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> signed main() { long long n; std::cin >> n; std::vector<long long> a(n); for (long long i = 0; i < (n); i++) std::cin >> a[i]; const long long INF = 1e18; long long mincount = INF; for (long long x = 0; x < (2); x++) { long long sum = a[0]; long long count = 0; if (sum...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python2
n = input() a = map(int ,raw_input().split()) if a[0] > 0: sign = 1 if a[0] < 0: sign = -1 c = 0 sum = a[0] for i in xrange(1,n): temp = a[i]+sum if temp == 0 and sum > 0: c += 1 sum = -1 continue if temp == 0 and sum < 0: c += 1 sum = 1 continue i...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans_a = 0, sum_a = 0; for (int i = 0; i < n; i++) { sum_a += a[i]; if ((i % 2 != 0) && (sum_a >= 0)) { ans_a += abs(sum_a) + 1; sum_a -= abs(sum_a) + 1; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef vector<vector<int> > vii; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < (int)n; i++) cin >> a[i]; long long sum = a[0], op_cnt = 0; for (int i = (int)1; i < (int)n; i++)...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
# coding: utf-8 # Here your code N = int(input()) a = [int(i) for i in input().split()] result = 0 before_sum =a[0] after_sum =a[0] for i in range(1,N): before_sum = after_sum after_sum = before_sum + a[i] if before_sum * after_sum > 0: if after_sum < 0: result += 1 - after_sum ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); int ju = 0; for (int i = 0; i < (int)(n); i++) { cin >> a[i]; if (i % 2 == 0 && a[i] >= 0) ju++; if (i % 2 == 1 && a[i] < 0) ju++; } long long int sum = 0, ans = 0; if (ju >= n / 2) { for (int i...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) a = list(map(int, input().split())) sum = a[0] change = 0 for i in range(1,n): val = 0 tempsum = sum+a[i] if sum < 0 and tempsum <=0: val = 1 - tempsum if sum > 0 and tempsum >=0: val = -1 - tempsum sum = tempsum + val change += abs(val) print(change)
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; class Main { int n; int[] a; public static void main(String[] args) { Scanner sc = new Scanner(System.in); Main m = new Main(sc); m.solve(); sc.close(); } Main(Scanner sc) { n = sc.nextInt(); a = new int[n]; for(int i=0;i<n;i++){ a[i] = sc.nextInt(); } } void solv...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932384626433832795; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; bool isDiffer(long long a, long long b) { if (b == 0) return false; if (((a > 0) && (b < 0)) || ((a < 0) && (b > 0))) return true; else return false; } i...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
require 'prime' include Math def max(a,b); a > b ? a : b end def min(a,b); a < b ? a : b end def swap(a,b); a, b = b, a end def gif; gets.to_i ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
#例の答えはあってる。 n=int(input()) x=list(map(int,input().split())) k=x[0] s="" if x[0]>0: s="True" else: s="Folus" l=0 for i in range(1,n): k+=x[i] if k>=0 and s=="True": l+=k+1 k=-1 s="Folus" elif k<=0 and s=="Folus": l+=k*(-1)+1 k=1 s="True" else: if s=="True": s="Folus" ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import copy n=int(input()) a=list(map(int,input().split())) b=copy.copy(a) ct1=0 if a[0]<=0: a[0]=1 ct1+=1-a[0] for i in range(1,n): if i%2==1: if sum(a[0:i+1])>=0: ct1+=sum(a[0:i+1])+1 a[i]=-sum(a[0:i])-1 else: if sum(a[0:i+1])<=0: ct1+=1-sum(a[0:i+1]) a[i]=-sum(a[0:i])+1 ct2=...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
# coding: utf-8 import math if __name__ == "__main__": n = int(input()) nums = list(map(int, input().split())) acm = nums[0] counts = 0 for num in nums[1:]: if acm * (acm+num)>0: counts += abs(acm+num)+1 acm = -acm//abs(acm) elif acm * (acm+num)<0: acm = acm+num else: if acm == 0: counts ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int32_t main() { uint64_t N; cin >> N; long long total, sign; unsigned long long count; cin >> total; if (total == 0) { total = 1; sign = 1; count = 1; } else { sign = total / abs(total); count = 0; } for (uint64_t i = 1; i < N; i++) { ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n-1);i>=0;i--) #define FOR(i,n,m) for(int i=n;i<=(int)(m);i++) #define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--) #define all(x) (x).begin(),(x).end() #define sz(x) int(x.size()) typedef long long ll; const int INF = 1...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
function Main(s) { var s = s.split("\n"); var n = parseInt(s[0], 10); var a = s[1].split(" ").map(e => parseInt(e, 10)); var acc = 0, cnt = 0, arr = []; for (var i = 0; i < n; i++) { acc += a[i]; if (i === 0) { if (acc === 0) { if (a[i + 1] >= 0) { acc--; cnt++; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long res, standard, n, a[100000], sum; long long ans = 1000000000000000LL; int get_sign(int x) { if (0 < x) return 1; else if (x < 0) return -1; else return 0; } int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; res = 0, standard =...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using vpii = vector<pair<int, int>>; using vpll = vector<pair<ll, ll>>; int main(void) { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll ans = 0; ll cur = A[0]; if (cur == 0) { ans++; int i = 1; w...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int f(vector<int> a, int sign) { int ans = 0; if (sign > 0 && a.at(0) <= 0) { ans += -a.at(0) + 1; a.at(0) += -a.at(0) + 1; } if (sign < 0 && a.at(0) >= 0) { ans += a.at(0) + 1; a.at(0) -= a.at(0) + 1; } int sum = a.at(0); for (int i = 1; i < a...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; int ans = 0; vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> a; vec.at(i) = a; } int now1 = 0, now2 = 0, cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { now1 += vec[i]; now2 += vec[i]; if (now1 ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input().strip()) A = list(map(int, input().strip().split(" "))) def solver(_sign): s = A[0] count = 0 if _sign and s <= 0: # head is positive count += abs(s) + 1 s = 1 elif s >= 0: # head is negative count += abs(s) + 1 s = -1 for a in A[1:]: prev =...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum = 0, f = 0, ans = 0; cin >> n; vector<long long int> a(10000000); for (int i = 0; i < n; i++) { cin >> a[i]; } sum += a[0]; if (sum > 0) { f = -1; } else if (sum < 0) { f = 1; } else { if (a[1] < 0) { ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { int n, a[100010]; long sgn, cont = 0, ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } cont += a[0]; if (cont > 0) sgn = 1; else if (cont < 0) sgn = -1; else { ans++; int i = 0; for (; a[i] == 0; i++) { sg...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) a = [int(i) for i in input().split()] ans1 = ans2 = 0 s = s2 = a[0] if a[0] < 0: s = 1 ans1 = -a[0] + 1 if a[0] > 0: s2 = -1 ans2 = a[0] + 1 for i in range(1, len(a)): s += a[i] if i % 2 == 1 and s >= 0: ans1 += s + 1 s = -1 elif i % 2 == 0 and s <= 0: ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> S(N + 1); for (int i = 1; i <= N; ++i) { cin >> S[i]; S[i] += S[i - 1]; } int ians = (1 << 30); for (int j = -1; j <= 1; j += 2) { vector<int> S_(S); int ans = 0; int add = 0; int sign = j; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
input() a = list(map(int, input().split())) s = a[0] ret = 0 for i in a[1:]: if s * i > 0: t = s + i k = 1 if t > 0 else -1 ret += k * t + 1 s = -k else: if s * (s+i) < 0: s = s+i else: ret += s+i+1 s = -1 if s > 0 else 1 print(ret)
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long a[200005] = {0}; int main() { long long n, i; cin >> n; for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); } long long sum1 = 0, sum2 = 0; long long ans1 = 0, ans2 = 0; sum1 += a[1], sum2 += a[1]; for (i = 2; i <= n; i++) { sum1 += a[i]; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
package main import "fmt" func main() { var n int fmt.Scan(&n) sum := 0 cnt := 0 plus := false a := make([]int, n) for i := 0; i < n; i++ { fmt.Scan(&a[i]) } var base int for i :=0; i <n; i++ { if a[i] != 0 { base = i break } } if base % 2 == 0 { plus = true } else { plus = false } i...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int &x : a) { cin >> x; } bool plus; long sum = 0; int count_plus = 0; plus = false; for (int i = 0; i < n; i++) { plus = !plus; sum += a.at(i); if (plus) { if (sum > 0) { ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) al = list(map(int, input().split())) m = n//2 mm = n % 2 temp = al[0] res = 0 def ddd(temp,al,m,mm,res): if temp > 0 and mm ==1: for i in range(1,m+1): temp +=al[i*2-1] if temp <0: pass else: res += temp+1 ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def z(s,l): for i in range(n-1): r=l+a[i+1] if r*l>=0: if l<=0: s+=1-r r=1 else: s+=1+r r=-1 l=r return s n=int(input()) a=list(map(int,input().split())) s1=0 l1=a[0] if a[0]<=0: s1=1-a[0] l1=1 s2=0 l2=a[0] if a[0]>=0: s1=a[0]-1 l1=-1 print(min(z(s1,l1),z(s2,l2)))
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> std::vector<int> seq, sum; int main() { int n; std::cin >> n; seq.resize(n); sum.resize(n); std::cin >> seq[0]; sum[0] = seq[0]; for (int i = 1; i < n; i++) { std::cin >> seq[i]; sum[i] = sum[i - 1] + seq[i]; } bool is_plus = true; long ans = 0; long dif = 0; if ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <cstdio> #include <algorithm> using namespace std; int main(){ int n; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) scanf(" %d", &a[i]); int S = a[0]; int j = 0; for (int i = 1; i < n; i++){ if (S * (S+a[i]) < 0){ S += a[i]; } else if ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def main(): n = int(input()) A = list(map(int, input().split())) res = 0 sums = [] for i in range(n): if i == 0: sums.append(sum(A[:i]) + A[i]) if A[i] == 0: index = -1 for j in range(n): if A[j] != 0: ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<long long> S1(N); vector<long long> S2(N); S1[0] = A[0]; S2[0] = 0; int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < N; i++) { if (i) { ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
N = int(input()) A = list(map(int,input().split())) ans1,ans2 = 0,0 res = A[0] for i in range(1,N): res += A[i] if i%2==1: if res >= 0: ans1 += res+1 res = -1 else: if res <= 0: ans1 -= res-1 res = 1 res = A[0] for i in range(1,N): res +=...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; long long A[100010] = {}; bool flag = false; long long tmp, sum; long long ans[] = {0, 0}; cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; if (A[0] == 0) { flag = true; A[0] = 1; ans[0]++; } tmp = 0, sum = 0; for (int...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int a[n], c[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) c[i] = a[i]; int count = 0, count2 = 0, sum = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { if (sum + a[i] <= 0) { int...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; long long n; vector<long long> a; long long count(long long sum) { long long cnt = 0; for (long long i = 1; i < n; ++i) { if (sum > 0) { sum += a[i]; if (sum >= 0) { cnt +...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int N; vector<int> a; int solve(bool b) { long long count = 0; long long sum = a[0]; if (a[0] == 0) { sum = b ? 1 : -1; count++; } else if (b && a[0] < 0) { sum = 1; count = 1 - a[0]; } else if (!b && a[0] > 0) { sum = -1; count = a[0] + 1;...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import numpy as np n = int(input()) L = np.array([int(i) for i in input().split()]) count = 0 s = L[0] #if L[0] == 0: # if L[1] > 0: # L[0] = -1 # else: # L[0] = 1 # count += 1 # print(L) loopnum = n//2 if n%2 == 0: loopnum -= 1 #+-+-... for i in range(loopnum): s = s + L[2*i+1] if s >= 0: s...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long n, ans1 = 0, ans2 = 0, sum1 = 0, sum2 = 0; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def solve(): n = int(input()) a = list(map(int, input().split())) i = 0 sum = 0 ans = 0 for i in range(n-1): sum += a[i] if sum > 0 and sum+a[i+1] > 0: tmp = -1 - sum ans += abs(tmp - a[i+1]) a[i+1] = tmp elif sum < 0 and sum+a[i+1]...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import copy n = int(input()) a = [int(i) for i in input().split()] b=a.copy() s0p = a[0] s0n = b[0] countp = 0 countn = 0 if a.count(0)==n: print(2*n+1) exit() """ if s0p<=0: while s0p<=0: s0p+=1 countp+=1 if s0n>=0: while s0n>=0: s0n-=1 countn+=1 """ for i in range(1,n): s1 = s0p+a[i] if ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } long long sum = 0; long long cnt1 = 0; for (int i = 0; i < N; i++) { sum += A[i]; if (i % 2 == 0 && sum <= 0) { cnt1 += 1 - sum; sum = ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int sign(int a) { if (a > 0) return 1; else if (a < 0) return -1; else return 0; } int main(void) { int n; cin >> n; int sum = 0, s = 1; int a; int num = 0; for (int i = 0; i < n; i++) { cin >> a; sum += a; if (i != 0 && (sign(s) ==...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def read_input(): n = int(input()) alist = list(map(int, input().split())) return n, alist def get_sign(x): if x > 0: return 1 elif x < 0: return -1 return 0 def submit(): n, alist = read_input() s = alist[0] sign = get_sign(s) edit = 0 for a in alist[1:]:...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<int> s(n); for (int &x : a) { cin >> x; } s.at(0) = a.at(0); for (int i = 1; i < n; i++) { s.at(i) = s.at(i - 1) + a.at(i); } int count = 0; if (a.at(0) == 0) { a.at(0)++; count++; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> unsigned solve(unsigned N, const std::vector<long> &a, int flag) { unsigned c = 0; long s = 0; for (unsigned n = 0; n < N; ++n) { long b = s + a[n]; if (n % 2 == flag) { if (b <= 0) { c += std::abs((+1) - b); s = +1; } else { s = b; } ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int c1 = 0, s1 = 0, c2 = 0, s2 = 0; for (int i = 0; i < n; i++) { s1 += a[i]; s2 += a[i]; if (i % 2 == 0) { if (s1 <= 0) { c1 += 1 - s1; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; if (a[0] == 0) { a[0] = 1; long long total = a[0]; long long temp; long long ans1 = 0; ans1++; for (int i = 1; i <...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vs = vector<string>; const int mod = 1000000007; class mint { public: long long x; mint(long long x = 0...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[100000]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int cnt = 0; int sum = 0; for (int i = 0; i < n; i++) { if (sum + a[i] == 0) { cnt++; if (i == 0) { sum = a[1] > 0 ? -1 : 1; } else { ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import numpy as np N = int(input()) a_s = input().split() for i in range(N): a_s[i] = int(a_s[i]) a_s = np.array(a_s) def get_sign(x): if x>0: return +1 elif x<0: return -1 else: return 0 ans = 0 S0 = None for i,a in enumerate(a_s): if i==0: S = a if S == ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
N = gets.to_i a = gets.split.map(&:to_i) # 偶数番目を負に ans_even = 0 a_even = a.dup # 奇数番目を負に ans_odd = 0 a_odd = a.dup if a_even[0] >= 0 while a_even[0] > 0 a_even[0] -= 1 ans_even += 1 end elsif a_odd[0] <= 0 while a_odd[0] < 0 a_odd[0] += 1 ans_odd += 1 end end sum_even = ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n=int(input()) a=list(map(int,input().split())) now=a[0] flag=abs(a[0])//a[0] c=0 #print(c,flag) for i in range(1,n): tmp=now+a[i] if not tmp*flag<0: c+=abs(flag*-1-tmp) now=flag*-1 else: now=tmp flag*=-1 #print(c,flag) print(c)
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932384626433832795; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; bool isDiffer(long long a, long long b) { if (b == 0) return false; if (((a > 0) && (b < 0)) || ((a < 0) && (b > 0))) return true; else return false; } i...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
n = gets.to_i arr = gets.chomp.split(" ").map(&:to_i) count = 0 def check(i,arr) if arr[i] > 0 arr[1] -= 1 elsif arr[i] < 0 arr[1] += 1 else if i == arr.size - 1 arr[1] += 1 return end check(i+1,arr) end end num = arr[0] + arr[1] if num == 0 if arr[2] > 0 arr[1] -= 1 ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include"bits/stdc++.h" using namespace std; int main(){ int n; cin>>n; vector<int> x; int temp,ans=0; for(int i=0;i!=n;++i){ cin>>temp; x.push_back(temp); } if(!x[0]){ x[0]=1; ++ans; int val,ind; for(int i=0;i!=n;++i){ if(!x[i]){ val=x[i]; ind=i; break; } } if((val>0 && ind%2) ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; using static AtCoderTemplate.MyAlgorithm; namespace AtCoderTemplat...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) original_A = [int(x) for x in input().split()] ans = [] for k in range(2): A = original_A.copy() count = 0 if k%2: if A[0] >= 0: A[0] = -1 count += (abs(A[0]) +1) else: if A[0] < 0: A[0] = 1 count += (abs(A[0]) +1) ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vb = vector<bool>; using vvb = vector<vb>; using mii = map<int, int>; using pqls = priority_qu...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
import System.IO import Control.Monad import Data.List main = do n <- getLine as <- fmap read . words <<= getLine putStrLn . show . head . [xs | xs <- iterate mani as, jouken n xs] mani [] = [] mani [a] = [a-1, a+1] mani (a:as) = [(a-1) : x | x <- mani as] ++ [(a+1) : x | x <- mani as] subsum xs j = sum . take j...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import sys n = int(input()) a = [int(n) for n in input().split()] sum = [0]*n sum[0] = a[0] ans = 0 for i in range(1,n): sum[i] = sum[i-1] while((sum[i]+a[i])*sum[i-1] >= 0): if(sum[i-1] > 0): ans+=sum[i-1] + a[i]+1 a[i]-=sum[i-1] + a[i]+1 else: ans+=1 - sum[i...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) a = list(map(int, input().split())) d1 = [0] * (n + 1) d2 = [0] * (n + 1) ans1 = 0 ans2 = 0 for i in range(n): d1[i+1] += d1[i] + a[i] d2[i+1] += d2[i] + a[i] # - + - + - の順番 for i in range(n): d1[i+1] = d1[i] + a[i] if(i % 2 == 0 and d1[i+1] >= 0): ans1 += abs(d1[i+1])+1 ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int DX[] = {1, 1, 0, -1, -1, -1, 0, 1}; int DY[] = {0, -1, -1, -1, 0, 1, 1, 1}; int n; ll a[100010]; ll hoge() { ll ans = 0; ll temp = 0; for (int(i) = 0; (i) < (n); (i)++) { if (temp > 0 && t...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) a = list(map(int,input().split())) res = 0 sum = 0 for i in range(n - 1): sum += a[i] if sum * (sum+a[i+1]) >= 0: if sum > 0: temp = -1 - sum-a[i+1] a[i+1] += temp res += abs(temp) else: temp = 1 - sum-a[i+1] a[i+1] += temp res += temp print(res)
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def read_input(): n = int(input()) alist = list(map(int, input().split())) return n, alist def get_sign(x): if x > 0: return 1 elif x < 0: return -1 return 0 def submit(): n, alist = read_input() s = alist[0] sign = get_sign(s) edit = 0 for a in alist[1:]:...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
n = int(input()) a = list(map(int,input().split())) ttl = a[0] cst = 0 if a[0]>0: flg = 1 elif a[0] == 0: for i in range(1,n): if a[i]==0: continue elif a[i]>0: cst += 1 ttl -= 1 flg = -1 break elif a[i]<0: cst += ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < (n); ++i) cin >> a[i]; int sum = 0; int sign = 1; int ans_p = 0; for (int i = 0; i < (n); ++i) { sum += a[i]; if ((sign > 0) && (sum <...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
N = int(input()) A = list(map(int, input().split())) ans = 0 prev_sm = A[0] # total to i - 1 for i in range(1, N): # if prev_sum is plus and a is more minus than prev_sum. if prev_sm > 0 and prev_sm + A[i] < 0: prev_sm += A[i] continue # if prev_sum is plus and a is larger than or equal to prev_sum. el...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; void answer1() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int& a_i : a) { cin >> a_i; } int count = 0; int sum = 0; int count2 = 0; int sum2 = 0; bool is_positive = a.at(0) > 0; for (int i = 0; i < a...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import sys n, *a = map(int, sys.stdin.read().split()) def main(): c1 = c2 = s1 = s2 = 0 for i in range(n): s1 += a[i] s2 += a[i] if i & 1: if s1 >= 0: c1 += s1 + 1 s1 = -1 if s2 <= 0: c2 += 1 - s2 s...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100000]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int preans, ans = 0, sum = 0; for (int i = 0, j = 0; j < 2; i++) { int presum = sum, cnt = 0; sum += a[i]; if (presum < 0) { if (sum <= 0) { while (sum <= 0...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long wa = a[0]; long long ans = 0; for (int i = 1; i < n; i++) { if (wa > 0) { wa += a[i]; if (wa > 0) { ans += wa + 1; wa -...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int sumi = 0; int sumi1 = 0; int countPlus = 0; int countMinus = 0; int[] a = new int[n]; for(int i = 0; i < n; i++) { a[i] = scan.nextInt(); } ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; int code(long long int n) { if (n <...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; vector<ll> a(N); for (int i = 0; i < N; i++) cin >> a.at(i); ll sumO = a.at(0), sumE = a.at(0), countO = 0, countE = 0; for (int i = 1; i < N; i++) { ll O = a.at(i), E = a.at(i); if (i % 2 == 0) { ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string divide[4] = {"dream", "dreamer", "erase", "eraser"}; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; int sum = 0; int plus = 0; for (int i = 0; i < n; ++i) { if (i % 2 == 0) { if (sum + a[i] <= 1) { plu...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int sign(int x) { if (x > 0) return 1; else if (x < 0) return 0; else return -1; } int f(int t, int pre, int s) { if (s == 0) return abs(-1 - pre - t); else return abs((1 - t) - pre); } int main() { int n, a[100005]; cin >> n; for (int i ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
N = int(input()) a = [int(i) for i in input().split()] sam = a[0] old = sam num = 0 for i in range(1, len(a)): sam += a[i] if sam >= 0 and old > 0: num += (abs(sam) + 1) sam -= (sam + 1) elif sam <= 0 and old < 0: num += (abs(sam) + 1) sam -= (sam - 1) old = sam print(num...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> static std::uint64_t solve(const std::vector<int>& va, int initSum, std::uint64_t initCnt = 0) { int sum = initSum; std::uint64_t cnt = initCnt; for (std::remove_reference<decltype(va)>::type::size_type i = 1; i < va.size(); i++) { auto nextSum = sum ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } long long sumi = 0, val1 = 0; int ne = 0; if (a.at(0) == 0) { while (a.at(ne) == 0) { if (ne == 0) val1++; else val1 += 2; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
object Main { def main(args: Array[String]): Unit = { import scala.io.StdIn.readLine val _ = readLine val datA = readLine.split(" ").map(_.toInt) val work = datA.map(a => (a, 0)).foldLeft((0, 0)){ case ((sum, count),(a, _)) => if (sum > 0) { if (sum + a >= 0) (-1, count + math.abs(sum +...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import numpy as np n = int(input()) a = list(map(int, input().split())) c = 0 sum = a[0] for i in range(1, n): if not (np.sign(sum) != np.sign(sum + a[i]) and sum + a[i] != 0): if sum > 0: c += a[i] + sum + 1 sum = -1 else: c += -a[i] - sum + 1 sum = 1...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python2
if __name__ == '__main__': N = input() array = raw_input().split() ans = 0 total = int(array[0]) totalZero = False if total == 0: totalZero = True flag = False if total >= 0: flag = True for a in array[1:]: if totalZero == True: ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #include <boost/range/irange.hpp> #include <boost/range/adaptors.hpp> using namespace std; using namespace boost; using namespace boost::adaptors; using uint = unsigned int; using ll = long long int; using ull = unsigned long long int; int main() { ll n; cin >> n; ll count{0}, s_n...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt(); int sum = 0, ans = 0, ans2 = 0; // 偶数位置までの和:正、奇数位置までの和:負 for(int i = 0 ; i < n ; i++) ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
program ec12; var a,s:array[0..100000] of longint; n,m,i,j,ans,sum1,sum2,ans1:longint; begin readln(n); ans:=0; ans1:=0; s[0]:=0; for i:=1 to n do read(a[i]); if a[1]>0 then begin sum1:=a[1]; ans:=0; ans1:=a[1]+1; sum2:=-1; end else begin if a[1]=0 then begin sum1:=1; sum2:=-1; ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
N = int(input()) A = list(map(int, input().split())) cntA, sumA = 0, 0 for i in range(N): sumA += A[i] if i % 2 == 0: if sumA < 0: cntA += abs(sumA) + 1 sumA += abs(sumA) + 1 else: if sumA > 0: cntA += abs(sumA) + 1 sumA -= abs(sumA) + 1 ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
parseInt(x) = parse(Int, x) function main() n = readline() |> parseInt a = map(parseInt, split(readline())) b = Array{Int}(n) k = 0 if a[1] > 0 b[1] = 1 k += abs(a[1]-1) else b[1] = -1 k += abs(a[1]+1) end for i in 2:n b[i] = a[i]+b[i-1] if b[i]*b[i-1] >= 0 if b[i-1] < 0 k += abs(b[i]-1) ...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; int solve(int sign) { int ans = 0; int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; if (sign * sum <= 0) { ans += 1 - sum * sign; sum = sign; } sign *= -1; } return ans; } int main() { ios::sync_with_stdio...
p03739 AtCoder Beginner Contest 059 - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4" ], "output": [ "0", "4", "8" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
n = gets.to_i as = gets.split.map(&:to_i) cnt1 = 0 sum = as[0] n.times.with_index(1) do |_,i| break if as[i].nil? prev = sum < 0 ? "n" : "p" tmp = sum sum += as[i] if prev == "n" if sum == 0 sum += 1 cnt1 += 1 elsif sum < 0 sum = 1 cnt1 += tmp.abs - as[i].abs + 1 end el...