prob_desc_description
stringlengths
63
3.8k
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
lang_cluster
stringclasses
2 values
src_uid
stringlengths
32
32
code_uid
stringlengths
32
32
lang
stringclasses
7 values
prob_desc_output_to
stringclasses
3 values
prob_desc_memory_limit
stringclasses
19 values
file_name
stringclasses
111 values
tags
listlengths
0
11
prob_desc_created_at
stringlengths
10
10
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_notes
stringlengths
4
3k
βŒ€
exec_outcome
stringclasses
1 value
difficulty
int64
-1
3.5k
βŒ€
prob_desc_input_from
stringclasses
3 values
prob_desc_time_limit
stringclasses
27 values
prob_desc_input_spec
stringlengths
28
2.42k
βŒ€
prob_desc_sample_outputs
stringlengths
2
796
source_code
stringlengths
42
65.5k
hidden_unit_tests
stringclasses
1 value
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
1c83bac9a1093c253707bc0a84acb10e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <math.h> int max(int a, int b); int main(int argc, char const *argv[]) { long long int players, rounds, n, sumaRounds = 0, res = 0, ma = 0; scanf("%I64d", &players); n = players; while(n--) { scanf("%I64d", &rounds); sumaRounds += rounds; if(rounds > ma){ ma = rounds; } } res = ceil((double)sumaRounds/(players-1)); res = max(res, ma); printf("%I64d\n", res); return 0; } int max(int a, int b) { int m = a; if (m < b) { m = b; } return m; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
7734d99f125edc7c663917509b4b0e73
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <math.h> int max(int a, int ); int main(int argc, char const *argv[]) { long long int players, rounds, n, sumaRounds = 0, res = 0, ma = 0; scanf("%I64d", &players); n = players; while(n--) { scanf("%I64d", &rounds); sumaRounds += rounds; if(rounds > ma){ ma = rounds; } } res = ceil((double)sumaRounds/(players-1)); res = max(res, ma); printf("%I64d\n", res); return 0; } int max(int a, int b) { int m = a; if (m < b) { m = b; } return m; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
52f64a4e5d2dc165a7219c7adf758018
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include<stdio.h> int main() { int i,n; scanf("%d",&n); long long int temp=0,a[n],ans=0; for(i=0;i<n;i++) { scanf("%lld",&a[i]); temp += a[i]; if(a[i]>ans) ans=a[i]; } temp=1+(temp-1)/(n-1); if(temp > ans) ans=temp; printf("%lld\n",ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
279e6373a46c27795e7a59cc13ac56b8
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main() { long long int n, i, a, max=0, sum=0; scanf("%lld", &n); for(i=0; i<n; i++) { scanf("%lld", &a); if(a>max) max=a; sum+=a; } long long int ans=(sum-1)/(n-1)+1; if(ans<max) ans=max; printf("%lld\n", ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
16c7f86767f399ac15cbc036e06afcb4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main() { long long int n, i, a, max=0, sum=0; scanf("%lld", &n); for(i=0; i<n; i++) { scanf("%lld", &a); if(a>max) max=a; sum+=a; } long long int ans=(sum-1)/(n-1)+1; if(ans<max) ans=max; printf("%lld\n", ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
a4fd6594cba810189b2b5e275362a986
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main(){ int cantidad; long long int i; long long int minimo_rondas=0; long long int suma=0; scanf("%d",&cantidad); int jugadores[cantidad]; for(i=0;i<cantidad;i++){ scanf("%d",&jugadores[i]); suma+=jugadores[i]; if(jugadores[i]>minimo_rondas) minimo_rondas=jugadores[i]; } for(i=minimo_rondas;i*(cantidad-1)<suma;i++); printf("\n%d",i); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
5d3a17a8b75afc47441c8069419a628f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main() { int v[100001]; int n, i; long long suma, mayor, resp; scanf("%d", &n); suma = 0; scanf("%I64d", &v[1]); suma += v[1]; mayor = v[1]; for(i = 2; i <= n; i++){ scanf("%I64d", &v[i]); suma += v[i]; if(v[i] > mayor) mayor = v[i]; } if(suma%(n-1) == 0) suma = suma/(n-1); else suma = 1+suma/(n-1); if(suma > mayor) resp = suma; else resp = mayor; printf("%I64d", resp); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
c8e2832f42a8ae25449836727a4144d4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include<stdio.h> #include<stdlib.h> #include<math.h> int main(){ int i,j,x,aux=0,n; double cant,count=0; int *friends; scanf("%d",&n); friends=malloc(n*sizeof(int)); for(i=0;i<n;i++){ friends[i]=0; } for(i=0;i<n;i++){ scanf("%d",&friends[i]); count+=friends[i]; } for(i=0;i<n;i++){ if(friends[i]>aux){ aux=friends[i]; } } cant=ceil(count/(n-1)); if(cant>aux){ printf("%d",(int)cant); } else{ printf("%d",aux); } //printf("%d",aux); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
21a02f8093432296f5838a31ef5f0866
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> long long n,m,a,i,s; main(){ scanf("%lld",&n); for(i=0;i<n;i++){ scanf("%lld",&a); if(a>m) m=a; s+=a; } printf("%lld",(m>(s-1)/(n-1)+1)?m:(s-1)/(n-1)+1); }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
cf2b0a9e9532def93b6db56798292cc5
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <stdlib.h> int main() { long long i, num, temp = 0, result = 0; scanf("%I64d",&num); long long a[num]; for(i = 0; i < num; i++) { scanf("%I64d", &a[i]); temp += a[i]; if(a[i] > result) result = a[i]; } temp = 1 + (temp - 1) / (num - 1); if(temp > result) result = temp; printf("%I64d", result); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
7ad3c9b422f59ac91e375fcff11a8c7a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main() { int n; long long sum=0; long long a,max=0; scanf("%d",&n); int x=n; while(x--) { scanf("%I64d",&a); if(a>max) max=a; sum+=a; } sum=n*max-sum; long long y=!((max-sum)%(n-1)==0); if(sum>=max) printf("%I64d\n",max); else printf("%I64d\n",max+(max-sum)/(n-1)+y); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
1ebb7ceb32a86c1d6f27b987ae098aa6
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main(){ int i, n; scanf("%d", &n); long long int temp = 0, a[n], ans = 0; for(i = 0; i < n; i++){ scanf("%I64d", &a[i]); temp += a[i]; if( a[i] > ans ) ans = a[i]; } temp = 1 + (temp-1)/(n-1); if(temp > ans) ans = temp; printf("%I64d\n", ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
c1a9062ec7d4fed884aa4ed8003baefb
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main() { int v[100001]; int n, i; long long suma, mayor, resp; scanf("%d", &n); suma = 0; scanf("%I64d", &v[1]); suma += v[1]; mayor = v[1]; for(i = 2; i <= n; i++){ scanf("%I64d", &v[i]); suma += v[i]; if(v[i] > mayor) mayor = v[i]; } if(suma%(n-1) == 0) suma = suma/(n-1); else suma = 1+suma/(n-1); if(suma > mayor) resp = suma; else resp = mayor; printf("%I64d", resp); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
7b4d116ec81d5cc0ce4d0fba69b2fa14
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include<stdio.h> #include<math.h> int main() { long long int suma=0,mayor=0,formula,num; int i,n; scanf("%d",&n); long long int v[n]; for(i=0;i<=n-1;i++) { scanf("%I64d",&num); v[i]=num; } for(i=0;i<=n-1;i++) { suma=suma+v[i]; if(mayor<v[i])mayor=v[i]; } formula=(suma-1)/(n-1)+1; if(mayor<formula)mayor=formula; printf("%I64d",mayor); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
9772f7f1fac44cae993815998e08284e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int n,num[100010]; int mx; long long calc(long long x) { int i; long long ret = 0; for(i=1;i<=n;i++) ret += x-num[i]; return ret; } long long work() { long long head = mx,tail = (long long)1e14,mid; while(head<tail) { mid = (head+tail)>>1; if(calc(mid)>=mid) tail = mid; else head = mid+1; } return head; } int main() { int i; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&num[i]); mx = mx>num[i]?mx:num[i]; } printf("%I64d",work()); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
615278cf437f10a82e5e5937f27b5f0b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <math.h> int main() { int u,k; scanf("%d",&u); long long int y[u], sum = 0, ans =0; for (int i = 0; i < u; ++i) { scanf("%I64d",&y[i]); sum = sum + y[i]; if (y[i]>ans) { ans = y[i]; } } sum = 1+(sum-1)/(u-1); if (sum > ans) { ans=sum; } printf("%d",ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
a2fe260b2e39b712faf83ea0dadaf5ee
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <stdlib.h> int main(){ long long i, n, r = 0, h = 0; scanf("%I64d",&n); long long jy[n]; for(i = 0; i < n; i++) { scanf("%I64d", &jy[i]); r += jy[i]; /* r funciona como nuestra variable rorarl de sumar las cantidades de rondas */ if(jy[i] > h) h = jy[i]; /*Ronda maxima posible a jugar*/ } /*r= (r-1)/(n-1)+1;*/ r = 1 + (r - 1) / (n - 1); /*r tenemos nuestro resultado*/ if(r > h){ h = r; } printf("%I64d", h); return 0;}
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
27218c98ecae47b8118b0dbd1d181338
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
/* ------------------------------------------------------------------- *INGENIERIA EN INFORMοΏ½TICA 2DO SEMESTRE LENGUAJE DE PROGRAMACIοΏ½N I -TRABAJO PRACTICO PROF. Ing. Diego Pedro Pinto Roa *Team(-): *Fabrizio - *Victor Rodolfo Gonzalez Galeano -5.528.793 ------------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> int main(){ long long i, n, temp = 0, mayor = 0; scanf("%I64d",&n); long long jugador[n]; for(i = 0; i < n; i++) { scanf("%I64d", &jugador[i]); temp += jugador[i]; /* Temp funciona como nuestra variable temporarl de sumar las cantidades de rondas */ if(jugador[i] > mayor) mayor = jugador[i]; /*Ronda maxima posible a jugar*/ } temp= (temp-1)/(n-1)+1; /*temp = 1 + (temp - 1) / (n - 1); /*Temp tenemos nuestro resultado*/ if(temp > mayor){ mayor = temp; } printf("%I64d", mayor); return 0;}
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
dd66493f8184c84c5859b1b12c355c27
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <stdlib.h> int main(){ long long i, n, r = 0, h = 0; scanf("%I64d",&n); long long jy[n]; for(i = 0; i < n; i++) { scanf("%I64d", &jy[i]); r += jy[i]; /* r funciona como nuestra variable rorarl de sumar las cantidades de rondas */ if(jy[i] > h) h = jy[i]; /*Ronda maxima posible a jugar*/ } r= (r-1)/(n-1)+1; /*r = 1 + (r - 1) / (n - 1); /*r tenemos nuestro resultado*/ if(r > h){ h = r; } printf("%I64d", h); return 0;}
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
fc0559c0e1cca8f965eb2863d21c14f2
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include<stdio.h> int main() { int n,i,max=0; long long int sum=0,ans=0; scanf ("%d",&n); int arr[n]; for (i=0;i<n;i++) { scanf ("%d",&arr[i]); sum+=arr[i]; if (arr[i]>max) max=arr[i]; } if (sum%(n-1)==0) ans=sum/(n-1); else ans=((sum/(n-1))+1); if (ans<max) ans=max; printf ("%lld\n",ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
1661d220ae0920519216e96b2455a19e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main() { long long int a[100005], s=0,max=0,j; int i,k,n; scanf("%d", &n); for(i=0;i<n;i++){ scanf("%I64d", &a[i]); s+= a[i]; if(max<a[i])max = a[i]; } j = s / (n-1); if(j * (n-1) < s) j++; if(j< max) j= max; printf("%I64d", j); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
7986f69dde8ed95b856011cacfe43485
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include<stdio.h> #include<limits.h> void swap(int *a,int *b) { int t=*a; *a=*b; *b=t; } int partition(int a[],int low,int high) { int x=a[high]; int j=low-1; int i; for(i=low;i<high;i++) { if(a[i]<=x) { j=j+1; swap(&a[i],&a[j]); } } swap(&a[j+1],&a[high]); return j+1; } void quicksort(int a[],int low,int high) { if(high>low) { int p=partition(a,low,high); quicksort(a,low,p-1); quicksort(a,p+1,high); } } int main() { int n; scanf("%d",&n); int a[n]; long long int max=INT_MIN; long long int i; long long int sum=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); sum+=a[i]; if(a[i]>max) max=a[i]; } //quicksort(a,0,n-1); // int max=a[n-1]; for(i=max;i*(n-1)<sum;i++); printf("%d\n",i); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
846d3806607aa55e13703f007f97dbd1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
/* ------------------------------------------------------------------- *INGENIERIA EN INFORMοΏ½TICA 2DO SEMESTRE LENGUAJE DE PROGRAMACIοΏ½N I -TRABAJO PRACTICO PROF. Ing. Diego Pedro Pinto Roa *Team(-): *Fabrizio - *Victor Rodolfo Gonzalez Galeano -5.528.793 ------------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> int main(){ long long i, n, temp = 0, mayor = 0; scanf("%I64d",&n); long long jugador[n]; for(i = 0; i < n; i++) { scanf("%I64d", &jugador[i]); temp += jugador[i]; /* Temp funciona como nuestra variable temporarl de sumar las cantidades de rondas */ if(jugador[i] > mayor) mayor = jugador[i]; /*Ronda maxima posible a jugar*/ } temp= (temp-1)/(n-1)+1; /*temp = 1 + (temp - 1) / (n - 1); /*Temp tenemos nuestro resultado*/ if(temp > mayor){ mayor = temp; } printf("%I64d", mayor); return 0;}
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
18ec3f18dbfbd9cf99804f9b05169fa3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int n; long long sum; int c(long long x) { if(n*x-sum>=x) return 1; else return 0; } int a[100100]; int main() { scanf("%d\n",&n); int i; int max=-1; sum=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]>max) max=a[i]; sum+=a[i]; } long long l=max,r=sum; while(r-l>1) { long long mid=(l+r)/2; if(c(mid)) r=mid; else l=mid; } if(c(l)) printf("%I64d\n",l); else printf("%I64d\n",r); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
342d88a9fee4c22292bbaae54910e56e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> int main(){ long long int n, mn = 0, mx, i, x, judge = 0; int play[100000]; scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d", &play[i]); for(i = 0; i < n; i++){ if(play[i] > mn) mn = play[i]; } mx = 2000000000; while(mx >= mn){ judge = 0; if(mx == mn) break; x = (mx + mn) / 2; for(i = 0; i < n; i++) judge += x - play[i]; if(judge >= x) mx = x; if(judge < x) mn = x + 1; } printf("%I64d", mn); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
7e89d06d0534582fad34abed22ab7be9
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
//PROBLEMA 5 MAFIA #include<stdio.h> #include<math.h> int main() { long long int sum = 0,mayor = 0,f,num; //f: formula int i,n; scanf("%d", &n); long long int v[n]; for(i = 0; i <= n-1 ; i++) { scanf("%I64d", &num); v[i] = num; } for(i=0 ; i <= n-1 ; i++) { sum = sum + v[i]; if(mayor < v[i]) mayor = v[i]; } f = (sum - 1)/(n - 1) + 1; if(mayor < f) mayor = f; printf("%I64d", mayor); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
e3cbe170afa5e8331f7b85a446a5a974
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> //#include<math.h> #define si(n) scanf("%d",&n) #define rep(i,n) for(i=0;i<n;i++) #define REP(i,a,b) for(i=a;i<b;i++) #define pn printf("\n") #define ps printf(" ") #define pi(n) printf("%d",n) #define pll(n) printf("%lld",n) #define sll(n) scanf("%lld",&n) #define ss(s) scanf("%s",s) #define mod 1000000000 int main(){int n,i,k;long long int ans=0,max=0; si(n); rep(i,n){si(k);ans+=k;max=(k>max?k:max);}//pll(ans);ps; ans=1+((ans-1)/(n-1));ans=(max>ans?max:ans); pll(ans); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
4ecce52391fa381630920bcaa5628f3a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
// // main.c // hahaha // // Created by θ΅΅ζ―… on 9/27/13. // Copyright (c) 2013 θ΅΅ζ―…. All rights reserved. // #include <stdio.h> typedef unsigned long long int ull; int n; int arr[100000]; int gao(long long int x){ int i; ull sum=0; for(i=0;i<n;i++){ if(x-arr[i]<0) return 0; sum+=x-arr[i]; } if(sum>=x) return 1; return 0; } int main(void){ int i; ull f=0,t=100000000000000; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",arr+i); while(f<t){ ull mid=(f+t)/2; if(gao(mid)){ t=mid; }else{ f=mid+1; } } printf("%I64u",f); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
5286fc996f3724a0f335a54ab01a6f8d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <stdlib.h> #define maxN 100010 #define max(a, b) (a > b ? a : b) const int INF = 1 << 30; int A[maxN]; int cmp( const void *a, const void *b ) { return *(int *)b - *(int *)a; } int main( void ) { int N; scanf("%i", &N); int i; for( i = 1; i <= N; i++ ) scanf("%i", &A[i]); qsort(A+1, N, sizeof(int), cmp); for( i = 1; i <= N-1; i++ ) A[i] -= A[N]; long long cnt = A[N]; for( i = 1; i <= N-1; i++ ) cnt -= A[1] - A[i]; cnt = max(0, cnt); printf("%lld\n", A[N] + A[1] + (cnt + N - 2) / (N-1)); return 0; }
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
In a single line print a single integer β€” the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
09f5623c3717c9d360334500b198d8e0
477e7a9bc45231e7dc0f7036e0b6f96b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "sortings", "math" ]
1380295800
["3\n3 2 2", "4\n2 2 2 2"]
NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
PASSED
1,600
standard input
2 seconds
The first line contains integer n (3 ≀ n ≀ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the i-th number in the list is the number of rounds the i-th person wants to play.
["4", "3"]
#include <stdio.h> #include <stdlib.h> #define maxN 100010 const int INF = 1 << 30; int A[maxN]; int cmp( const void *a, const void *b ) { return *(int *)b - *(int *)a; } int main( void ) { int N; scanf("%i", &N); int i; for( i = 1; i <= N; i++ ) scanf("%i", &A[i]); qsort(A+1, N, sizeof(int), cmp); for( i = 1; i <= N-1; i++ ) A[i] -= A[N]; long long ans; int lo = A[1], hi = 1 << 30, mid; while( lo <= hi ) { mid = (lo + hi) / 2; long long cnt = A[N]; for( i = 1; i <= N-1; i++ ) cnt -= mid - A[i]; if( cnt <= 0 ) { ans = A[N] + mid; hi = mid - 1; } else { lo = mid + 1; } } printf("%lld\n", ans); return 0; }
You are given a rooted tree with n vertices. In each leaf vertex there's a single integer β€” the number of apples in this vertex. The weight of a subtree is the sum of all numbers in this subtree leaves. For instance, the weight of a subtree that corresponds to some leaf is the number written in the leaf.A tree is balanced if for every vertex v of the tree all its subtrees, corresponding to the children of vertex v, are of equal weight. Count the minimum number of apples that you need to remove from the tree (specifically, from some of its leaves) in order to make the tree balanced. Notice that you can always achieve the goal by just removing all apples.
Print a single integer β€” the minimum number of apples to remove in order to make the tree balanced. Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the sin, cout streams cin, cout or the %I64d specifier.
C
db1c28e9ac6251353fbad8730f4705ea
62fc0a86e1cdcb2e4a49a036b865ef63
GNU C
standard output
256 megabytes
train_002.jsonl
[ "number theory", "dfs and similar", "trees" ]
1380295800
["6\n0 0 12 13 5 6\n1 2\n1 3\n1 4\n2 5\n2 6"]
null
PASSED
2,100
standard input
2 seconds
The first line contains integer n (2 ≀ n ≀ 105), showing the number of vertices in the tree. The next line contains n integers a1, a2, ..., an (0 ≀ ai ≀ 108), ai is the number of apples in the vertex number i. The number of apples in non-leaf vertices is guaranteed to be zero. Then follow n - 1 lines, describing the tree edges. Each line contains a pair of integers xi, yi (1 ≀ xi, yi ≀ n, xi ≠ yi) β€” the vertices connected by an edge. The vertices are indexed from 1 to n. Vertex 1 is the root.
["6"]
#include <stdio.h> #include <stdlib.h> /* http://codeforces.com/contest/349/submission/12948604 (Dukkha) */ #define MAX 1e13 struct L { struct L *next; struct V *v; }; struct V { struct L *list; long long sum, unit; int a; } **vv; struct V *new_V(int a) { struct V *v = calloc(1, sizeof *v); v->a = a; return v; } void list_add(struct V *u, struct V *v) { struct L *x = malloc(sizeof *x); x->v = v; x->next = u->list, u->list = x; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } void dfs(struct V *p, struct V *u) { struct V *v; struct L *x; long long min; int cnt; cnt = 0; for (x = u->list; x != NULL; x = x->next) { v = x->v; if (v != p) cnt++; } if (cnt == 0) { u->sum = u->a; u->unit = 1; return; } u->unit = 1; for (x = u->list; x != NULL; x = x->next) { v = x->v; if (v != p) { long long d; dfs(u, v); if (v->sum == 0) return; d = gcd(u->unit, v->unit); if (u->unit / d > MAX / v->unit) return; u->unit = u->unit / d * v->unit; } } min = 1e18; for (x = u->list; x != NULL; x = x->next) { v = x->v; if (v != p && min > v->sum / u->unit) min = v->sum / u->unit; } u->sum = min * u->unit * cnt; u->unit *= cnt; } int main() { long long sum; int n, h, i, j; scanf("%d", &n); vv = malloc(n * sizeof *vv); sum = 0; for (i = 0; i < n; i++) { int a; scanf("%d", &a); sum += a; vv[i] = new_V(a); } for (h = 0; h < n - 1; h++) { scanf("%d%d", &i, &j); i--, j--; list_add(vv[i], vv[j]); list_add(vv[j], vv[i]); } dfs(NULL, vv[0]); printf("%lld\n", sum - vv[0]->sum); return 0; }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
b1f38c5ea5dff4efa5a1ebadd6ca86df
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include <stdio.h> #include <stdlib.h> int main() { float n, s, i = 0, max = -1; scanf("%f %f", &n, &s); for(i = 0; i < n; i++) { float x, y; scanf("%f %f", &x, &y); max = s>= x+y/100? (max< 100-y? (y == 0 && max == -1? 0: (y == 0? max: 100-y)): max): max; } printf("%d", (int)max); }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
5115e321399097d9d96cc7390036d61a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include <stdlib.h> #include <stdio.h> #include <string.h> double comp(double v, int exp); int main(void) { int n, d, i, ans = -1, cd, cc; scanf("%d%d", &n, &d); for (i = 0; i < n; i++) { scanf("%d%d", &cd, &cc); if (cd * 100 + cc <= d * 100 && (100 - cc) % 100 > ans) ans = (100 - cc) % 100; } printf("%d\n", ans); return 0; } double comp(double v, int exp) { if (exp == 0) return 1; if (exp == 1) return v; double ret = comp(v, exp >> 1); ret *= ret; if (exp & 1) ret *= v; return ret; }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
6822ae56c2dac01b42a9e9c57a918424
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include<stdio.h> int main () { int n,s,x,y,ans=100,i,count=0; scanf("%d %d",&n,&s); for(i=1; i<=n; i++) { scanf("%d %d",&x,&y); if(x<s || ((x==s) && y==0)) { if(y && y<ans) ans=y; } else count++; } ans=100-ans; if(count==n) printf("-1\n"); else printf("%d\n",ans); return 0; }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
c771c9182276bb6dc639d90458f820e1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include<stdio.h> int main() { int n,s,i,a,b,max=0,count=0; scanf("%d %d",&n,&s); for(i=0;i<n;i++) { scanf("%d %d",&a,&b); if((a<s)||(a==s&&b==0)) { if(((100-b)>max)&&b!=0) max=100-b; count++; } } if(max!=0 || count!=0) printf("%d",max); else printf("-1"); return 0; }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
7fe519f2d7d6f9225f330530cff28471
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<stdbool.h> int main() { int n; int s; bool flag=false; long long int max=0; scanf("%i %i", &n, &s); float x[100]; float y[100]; for(int i=0;i<n;i++) { scanf("%f %f", &x[i], &y[i]); } for(int i=0;i<n;i++) { if(s>=(x[i]+y[i]/100)) { flag=true; if(max<(100-y[i]) && y[i]>0) max=100-y[i]; } } if(flag) printf("%llu\n", max); else printf("-1\n"); }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
0db4ebddecf7d4987e9f4b29f042669d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include <stdio.h> int main() { int m,n; scanf("%d%d",&m,&n); int arr[m][2]; for(int i=0;i<m;i++) { scanf("%d",&arr[i][0]); scanf("%d",&arr[i][1]); } int ig=-1,ct=0; for(int i=0;i<m;i++) { if((arr[i][0]<n) || ((arr[i][0]==n) && (arr[i][1]==0))) { ct++; if(ig<(100-arr[i][1]) && arr[i][1]!=0) ig=100-arr[i][1]; } } if(ct>0 && ig==-1) printf("0"); else printf("%d",ig); }
Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town.Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there are n types of sugar in the supermarket, maybe he able to buy one. But that's not all. The supermarket has very unusual exchange politics: instead of cents the sellers give sweets to a buyer as a change. Of course, the number of given sweets always doesn't exceed 99, because each seller maximizes the number of dollars in the change (100 cents can be replaced with a dollar).Caisa wants to buy only one type of sugar, also he wants to maximize the number of sweets in the change. What is the maximum number of sweets he can get? Note, that Caisa doesn't want to minimize the cost of the sugar, he only wants to get maximum number of sweets as change.
Print a single integer representing the maximum number of sweets he can buy, or -1 if he can't buy any type of sugar.
C
91be5db48b44a44adff4c809ffbb8e3e
daa86d4cd49f7b8b3e502e49598d0576
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "brute force" ]
1409383800
["5 10\n3 90\n12 0\n9 70\n5 50\n7 0", "5 5\n10 10\n20 20\n30 30\n40 40\n50 50"]
NoteIn the first test sample Caisa can buy the fourth type of sugar, in such a case he will take 50 sweets as a change.
PASSED
1,200
standard input
1 second
The first line contains two space-separated integers n, s (1 ≀ n, s ≀ 100). The i-th of the next n lines contains two integers xi, yi (1 ≀ xi ≀ 100;Β 0 ≀ yi &lt; 100), where xi represents the number of dollars and yi the number of cents needed in order to buy the i-th type of sugar.
["50", "-1"]
#include<stdio.h> int main() { int n,s,x,y,r,i,max=0,c=0; scanf("%d %d",&n,&s); for(i=1;i<=n;i++) { scanf("%d %d",&x,&y); if(x+(y/100.0)<=(s)) { if(y!=0&&y<100) { r=100-y; if(max<r) { max=r; } } } else { c++; } } if(c==n) { printf("-1\n"); } else if(max==0) { printf("0\n"); } else { printf("%d\n",max); } return 0; }
Dreamoon likes strings. Today he created a game about strings:String $$$s_1, s_2, \ldots, s_n$$$ is beautiful if and only if for each $$$1 \le i &lt; n, s_i \ne s_{i+1}$$$.Initially, Dreamoon has a string $$$a$$$. In each step Dreamoon can choose a beautiful substring of $$$a$$$ and remove it. Then he should concatenate the remaining characters (in the same order).Dreamoon wants to use the smallest number of steps to make $$$a$$$ empty. Please help Dreamoon, and print any sequence of the smallest number of steps to make $$$a$$$ empty.
For each test case, in the first line, you should print $$$m$$$: the smallest number of steps to make $$$a$$$ empty. Each of the following $$$m$$$ lines should contain two integers $$$l_i, r_i$$$ ($$$1 \leq l_i \leq r_i \leq |a|$$$), denoting, that the $$$i$$$-th step is removing the characters from index $$$l_i$$$ to $$$r_i$$$ in the current string. (indices are numbered starting from $$$1$$$). Note that after the deletion of the substring, indices of remaining characters may change, and $$$r_i$$$ should be at most the current length of $$$a$$$. If there are several possible solutions, you can print any.
C
1cb409e072d38270a5d84afd86b599a6
ae7b3f1d1f58641670ea9a75335a9d4e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "data structures", "constructive algorithms" ]
1585924500
["4\naabbcc\naaabbb\naaa\nabacad"]
null
PASSED
3,100
standard input
2 seconds
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 200\,000$$$), denoting the number of test cases in the input. For each test case, there's one line with a non-empty string of lowercase Latin letters $$$a$$$. The total sum of lengths of strings in all test cases is at most $$$200\,000$$$.
["3\n3 3\n2 4\n1 2\n3\n3 4\n2 3\n1 2\n3\n1 1\n1 1\n1 1\n1\n1 6"]
#include <stdio.h> #include <string.h> #define N 200000 #define A 26 int max(int a, int b) { return a > b ? a : b; } int main() { int t; scanf("%d", &t); while (t--) { static char cc[N + 1]; static int kk[A], kk_[N + 1], qu[N + 1], ll[N + 1]; int n, m, h, i, k, a, cnt, ans; scanf("%s", cc), n = strlen(cc); memset(kk, 0, sizeof kk); for (i = 1; i < n; i++) if (cc[i] == cc[i - 1]) kk[cc[i] - 'a']++; memset(kk_, 0, (n + 1) * sizeof *kk_); m = 0, k = 0; for (a = 0; a < A; a++) { kk_[kk[a]]++; m += kk[a], k = max(k, kk[a]); } m = (m + 1) / 2; ans = max(m, k) + 1; memset(ll, -1, (n + 1) * sizeof *ll); cnt = 0; for (i = 1; i < n && k < m; i++) if (cc[i] == cc[i - 1]) { if (cnt && cc[qu[cnt - 1]] != cc[i]) { ll[i] = qu[--cnt]; a = cc[ll[i]] - 'a', kk_[kk[a]]--, kk[a]--, kk_[kk[a]]++; a = cc[i] - 'a', kk_[kk[a]]--, kk[a]--, kk_[kk[a]]++; if (kk_[k] == 0) k--; m--; } else qu[cnt++] = i; } for (a = 0; a < A; a++) if (kk[a] >= m) break; for ( ; i < n; i++) if (cc[i] == cc[i - 1]) { if (cnt && (cc[qu[cnt - 1]] == a + 'a') != (cc[i] == a + 'a')) ll[i] = qu[--cnt]; else qu[cnt++] = i; } i = 0; for (h = 0; h < cnt; h++) ll[qu[h]] = i, i = qu[h]; ll[n] = i; cnt = 0; printf("%d\n", ans); for (i = 0; i <= n; i++) { if (ll[i] != -1) { int l, r; r = cnt; while (cnt && qu[cnt - 1] >= ll[i]) cnt--; l = cnt + 1; printf("%d %d\n", l, r); } qu[cnt++] = i; } } return 0; }
Dreamoon likes strings. Today he created a game about strings:String $$$s_1, s_2, \ldots, s_n$$$ is beautiful if and only if for each $$$1 \le i &lt; n, s_i \ne s_{i+1}$$$.Initially, Dreamoon has a string $$$a$$$. In each step Dreamoon can choose a beautiful substring of $$$a$$$ and remove it. Then he should concatenate the remaining characters (in the same order).Dreamoon wants to use the smallest number of steps to make $$$a$$$ empty. Please help Dreamoon, and print any sequence of the smallest number of steps to make $$$a$$$ empty.
For each test case, in the first line, you should print $$$m$$$: the smallest number of steps to make $$$a$$$ empty. Each of the following $$$m$$$ lines should contain two integers $$$l_i, r_i$$$ ($$$1 \leq l_i \leq r_i \leq |a|$$$), denoting, that the $$$i$$$-th step is removing the characters from index $$$l_i$$$ to $$$r_i$$$ in the current string. (indices are numbered starting from $$$1$$$). Note that after the deletion of the substring, indices of remaining characters may change, and $$$r_i$$$ should be at most the current length of $$$a$$$. If there are several possible solutions, you can print any.
C
1cb409e072d38270a5d84afd86b599a6
93a7c38bb4fabfb9cc74518e6bb8b2cb
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "data structures", "constructive algorithms" ]
1585924500
["4\naabbcc\naaabbb\naaa\nabacad"]
null
PASSED
3,100
standard input
2 seconds
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 200\,000$$$), denoting the number of test cases in the input. For each test case, there's one line with a non-empty string of lowercase Latin letters $$$a$$$. The total sum of lengths of strings in all test cases is at most $$$200\,000$$$.
["3\n3 3\n2 4\n1 2\n3\n3 4\n2 3\n1 2\n3\n1 1\n1 1\n1 1\n1\n1 6"]
#include <stdio.h> #include <string.h> #define maxn 200010 char s[maxn]; int cnt[30],n,last,vn,gn,an; struct node1{ int len; char c; }v[maxn],g[maxn]; struct node2{ int l,r; }ans[maxn]; int main(){ int t,i,tmp,m,tot,l,r,j; char dom; scanf("%d",&t); while(t--){ vn=gn=an=0; scanf("%s",s); n=strlen(s); last=0; for(i=0;i<n-1;i++) if(s[i]==s[i+1])vn++,v[vn].len=i+1-last,v[vn].c=s[i],last=i+1; for(i=0;i<26;i++)cnt[i]=0; for(i=1;i<=vn;i++)cnt[v[i].c-'a']++; tmp=0,m=vn,tot=0,dom=-1; for(i=0;i<26;i++) if(cnt[i]>0&&2*cnt[i]>=m)dom='a'+i; for(i=1;i<=vn;i++){ v[i].len+=tmp; if(gn&&v[i].c!=g[gn].c&&(dom==-1||v[i].c==dom||g[gn].c==dom)){ cnt[v[i].c-'a']--,cnt[g[gn].c-'a']--,m-=2; l=g[gn].len,r=l+v[i].len; an++,ans[an].l=l,ans[an].r=r; tot+=r-l,gn--,tmp=l-(gn?g[gn].len:0); for(j=0;j<26;j++) if(cnt[j]>0&&2*cnt[j]>=m)dom='a'+j; }else{ if(gn)tmp=g[gn].len+v[i].len,g[++gn].len=tmp,g[gn].c=v[i].c; else gn++,g[gn].len=0+v[i].len,g[gn].c=v[i].c; tmp=0; } } last=0; for(i=1;i<=gn;i++){ an++,ans[an].l=0,ans[an].r=g[i].len-last; tot+=g[i].len-last,last=g[i].len; } an++,ans[an].l=0,ans[an].r=n-tot; printf("%d\n",an); for(i=1;i<=an;i++)printf("%d %d\n",ans[i].l+1,ans[i].r); } return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
ab466d3079eca06b2bce5f9a215308d7
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include<stdio.h> #include<string.h> int main() { char str[1005][1005]; int len[1005],i=0,max=0,j,k,flag=0; while(gets(str[i])) { len[i]=strlen(str[i]); if(max<len[i])max=len[i]; i++; } for(j=0;j<max+2;j++) printf("*"); printf("\n"); for(j=0;j<i;j++) { printf("*"); for(k=0;k<(max-len[j]+flag)/2;k++) printf(" "); printf("%s",str[j]); for(k=0;k<(max-len[j]+1-flag)/2;k++) printf(" "); printf("*\n"); if(max%2!=len[j]%2)flag=1-flag; } for(j=0;j<max+2;j++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
628348d8ac3b6d655c3a1e87582b3071
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> int main() { char s[2000][2000],c, str[2000]; int i = 0 , j = 0 , m , p, l, k,alt; while( gets(str) ) { strcpy(s[j],str); j++; } i = 0; m = 0; while(i < j) { if(strlen(s[i]) > m) m = strlen(s[i]); i++; } i = 0; while(i < m + 2) { printf("*"); i++; } printf("\n"); i = 0; alt = 1; while(i < j) { k = strlen(s[i]); l = m - k; printf("*"); p = 1; if(l % 2 == 0) { while(p <= l / 2) { printf(" "); p++; } } else { if(alt) { while(p <= l / 2) { printf(" "); p++; } } else { while(p <= l / 2) { printf(" "); p++; } printf(" "); } } printf("%s",s[i]); p = 1; if(l % 2 == 0) { while(p <= l / 2) { printf(" "); p++; } } else { if(alt) { while(p <= l / 2) { printf(" "); p++; } printf(" "); alt--; } else { while(p <= l / 2) { printf(" "); p++; } alt++; } } printf("*\n"); i++; }//end output i = 0; while(i < m + 2) { printf("*"); i++; } printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
76a4826fe0ca93025f80937eccb37103
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> char ch[1005][1005]; int main() { int len,i=0,n,max=0,j,k=0; while (gets(ch[i])!=NULL) { len = strlen(ch[i]); if (max < len) max = len; i++; } /* while (gets(ch[i])&&ch[i][0]!='0') { len = strlen(ch[i]); if (max < len) max = len; i++; }*/ n = i; for (i=0;i<max+2;i++) printf("*"); printf("\n"); for (i=0;i<n;i++) { printf("*"); len = strlen(ch[i]); for (j=0; j<(max - len + k)/2; j++) printf(" "); printf("%s",ch[i]); for (j=0; j<(max - len + 1 - k)/2; j++) printf(" "); if ((max-len)%2!=0) k = 1 - k; printf("*\n"); } for (j=0;j<max+2;j++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
37117a73595df5217ca1c4fa8dda0d73
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include<stdio.h> #include<string.h> int main() { int i=0,max=0,l,c,k=1,j=0,b=0,m; char s[1001][1001]; for(i=0;gets(s[i])!=NULL;i++) { l=strlen(s[i]); if(l>=max)max=l; } for(j=0;j<max+2;j++)printf("*");printf("\n"); for(j=0;j<i;j++) { printf("*"); l=strlen(s[j]); if((max-l)%2==0)c=b=(max-l)/2; else { if(k)b=(max-l)/2,c=b+1; else c=(max-l)/2,b=c+1; if(k==0)k=1;else k=0; } for(m=0;m<b;m++)printf(" "); printf("%s",s[j]); for(m=0;m<c;m++)printf(" ");printf("*");printf("\n"); } for(j=0;j<max+2;j++)printf("*");printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
275cbb84ec97bfe1427e1fffddbe01e3
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include<stdio.h> int main() { long long int i,j,k,a,c,e=0,d,c1; long long int b[1002]; char s[1002][1002]; while(gets(s[i])!=NULL) { b[i]=strlen(s[i]); if(a<b[i]) a=b[i]; i++; } for(k=0;k<a+2;k++) printf("*"); printf("\n"); for(j=0;j<i;j++) { if((a-b[j])%2==0) { c=(a-b[j])/2; printf("*"); for(k=0;k<c;k++) printf(" "); printf("%s",s[j]); for(k=0;k<c;k++) printf(" "); printf("*");} else {c=(a-b[j])/2; if(e%2==0) {c1=c;d=c+1;} else{c1=c+1;d=c;} printf("*"); for(k=0;k<c1;k++) printf(" "); printf("%s",s[j]); for(k=0;k<d;k++) printf(" "); printf("*"); e++;} printf("\n"); } for(k=0;k<a+2;k++) printf("*"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
f7e110d730f454bad3495936fe50227e
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include<string.h> #include<math.h> int main() { int i, n, maxl = 0,b=0, t=0,dir, l=1,c=0,j,p; char a[1001][1001]; while(gets(a[t])) { n = strlen(a[t]); if(maxl < n) maxl = n; t++; } for(i=0;i<maxl+2;i++) printf("*"); printf("\n"); for(i=0;i<t;i++) { printf("*"); n = strlen(a[i]); p = maxl - n; if(n%2 == 0 && maxl%2 != 0 || n%2 != 0 && maxl%2 == 0) dir = 1; else dir = 0; if(dir==1 && l==1) { b = (p)/2; c = b + 1; l=0; } else if(dir==1 && l == 0) { c = (p)/2; b = c + 1; l=1; } else if(dir==0) { b=c = (p)/2; } for(j=0;j<b;j++) printf(" "); printf("%s", a[i]); for(j=0;j<c;j++) printf(" "); printf("*\n"); } for(i=0;i<maxl+2;i++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
ff2d3a2b345e4103788a676382ef7c40
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> main() { int mx=0,l,k,i=0; char a[1001][1001],j=0; while(gets(a[i])) { if(strlen(a[i])>mx) mx=strlen(a[i]); i++; } for(l=0; l<=mx+1; l++) printf("*"); printf("\n"); for(k=0; k<i; k++) { printf("*"); if((mx-strlen(a[k]))%2!=0) j++; if(j%2!=0) { for(l=((mx-strlen(a[k]))/2); l>0; l--) printf(" "); printf("%s",a[k]); for(l=mx-((mx-strlen(a[k]))/2)-strlen(a[k]); l>0; l--) printf(" "); printf("*\n"); } else { for(l=mx-((mx-strlen(a[k]))/2)-strlen(a[k]); l>0; l--) printf(" "); printf("%s",a[k]); for(l=((mx-strlen(a[k]))/2); l>0; l--) printf(" "); printf("*\n"); } } for(l=0; l<=mx+1; l++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
a401e5c0ab684bc8684eac67f66b88be
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include<string.h> #include<stdio.h> main() { int i=0,j,l,n,r,m=0,c=0; char word[1000][1000]; while(gets(word[i])){ l=strlen(word[i]); if(l>m) m=l; i++; } n=i; for(i=0;i<m+2;i++) printf("*"); printf("\n"); for(i=0;i<n;i++){ l=strlen(word[i]); r=(l+m)/2; if((l+m)%2==1){ r+=c; c=(c+1)%2; } printf("*%*s",r,word[i]); for(;r<m;r++) printf(" "); printf("*\n"); } for(i=0;i<m+2;i++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
eceaaec740f5a279cdbf0037636bae63
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> int main() { char word[1001][1001] = { 0, }; int wordLen = 0; int i, j; int maxLen = 0; int start = 0; int flag = 0; int len; for (wordLen = 0; gets(word[wordLen]) != NULL; wordLen++) maxLen = maxLen < strlen(word[wordLen]) ? strlen(word[wordLen]) : maxLen; for (i = 0; i < maxLen+2; i++) printf("*"); printf("\n"); for (i = 0; i < wordLen; i++) { len = maxLen - strlen(word[i]); start = len / 2; if (len & 1) { start += flag; flag = 1 - flag; } printf("*"); for (j = 0; j < start; j++) printf(" "); printf("%s", word[i]); for (j = start+1; j <= len; j++) printf(" "); printf("*\n"); } for (i = 0; i < maxLen + 2; i++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
0747b7722bda11a0c48e8fc229883997
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include<stdio.h> #include<string.h> int main(){ int i,j,k,l,n,m,z[1005],max = 0,nu=0; char c,s[1005][1005]; i = 0; int flag1 = 0; c = getchar(); while(c != EOF){ l = 0; s[i][l] = c; while(c != '\n' && c!= EOF){ l++; c = getchar(); s[i][l] = c; } s[i][l]='\0'; z[i] = l; if(z[i]>max) max = z[i]; i++; if(c==EOF) break; c = getchar(); } for(j=0;j<max+2;j++) printf("*"); printf("\n"); int flag = 1; for(j=0;j<=i-1;j++){ printf("*"); if((max-z[j])%2==0){ for(k=0;k<(max-z[j])/2;k++) printf(" "); printf("%s",s[j]); for(k=0;k<(max-z[j])/2;k++) printf(" "); printf("*"); } else{ if(flag==1){ for(k=0;k<(max-z[j])/2;k++) printf(" "); printf("%s",s[j]); for(k=0;k<(max-z[j])/2+1;k++) printf(" "); flag = 0; } else{ for(k=0;k<(max-z[j])/2+1;k++) printf(" "); printf("%s",s[j]); for(k=0;k<(max-z[j])/2;k++) printf(" "); flag = 1; } printf("*"); } printf("\n"); } for(j=0;j<max+2;j++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
5b258855bbe17efbb1bef17ca376b087
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> int main() { char s[1000][1005]; int n = 0, max = 0, f = 0, i, j; int a[1000]; while (fgets(s[n], 1005, stdin) != NULL) { a[n] = strlen(s[n]) - 1; s[n][a[n]] = '\0'; if (a[n] > max) max = a[n]; n++; } for (i = 0; i < max + 2; i++) putchar('*'); puts(""); for (i = 0; i < n; i++) { int x = (max - a[i]) / 2; putchar('*'); if ((max - a[i]) % 2 == 0) { for (j = 0; j < x; j++) putchar(' '); printf("%s", s[i]); for (j = 0; j < x; j++) putchar(' '); } else { if (f == 0) { for (j = 0; j < x; j++) putchar(' '); printf("%s", s[i]); for (j = 0; j < x + 1; j++) putchar(' '); } else { for (j = 0; j < x + 1; j++) putchar(' '); printf("%s", s[i]); for (j = 0; j < x; j++) putchar(' '); } f ^= 1; } puts("*"); } for (i = 0; i < max + 2; i++) putchar('*'); puts(""); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
9222313761adba317dd05fcf2b2ddb96
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> #define MAX_SIZE 1024 int main(void) { char line[MAX_SIZE][MAX_SIZE]; int max_length = 0, closing_left = 1, line_counter = 0; int i, j, k, length; i = 0; while(fgets(line[i], MAX_SIZE, stdin)) { length = strlen(line[i]); if(length > max_length) { max_length = length; } i++; line_counter++; } //print the top floor for(i=0; i<max_length+1; i++) printf("*"); printf("\n"); //TODO finish the to the left or to the right edge and bringing them closer left or right alternatively for(i=0; i<line_counter; i++) { length = strlen(line[i]); printf("*"); j = max_length - length; //center if(!(j%2)) { for(k=0; k<j/2; k++) printf(" "); for(k=0; k<length-1; k++) printf("%c", line[i][k]); for(k=0; k<j/2; k++) printf(" "); } else { if(closing_left) { for(k=0; k<j/2; k++) printf(" "); for(k=0; k<length-1; k++) printf("%c", line[i][k]); for(k=0; k<j/2+1; k++) printf(" "); closing_left = 0; } else { for(k=0; k<j/2+1; k++) printf(" "); for(k=0; k<length-1; k++) printf("%c", line[i][k]); for(k=0; k<j/2; k++) printf(" "); closing_left = 1; } } printf("*\n"); } //print the bottom floor for(i=0; i<max_length+1; i++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
53c85102d2477ad1ac3620d1f2b6e540
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> #define MAX_SIZE 1024 typedef struct { char string[MAX_SIZE]; int length; }data; int main(void) { data line[MAX_SIZE]; int max_length = 0, closing_left = 1, line_counter = 0; int i, j, k; while(fgets(line[line_counter].string, MAX_SIZE, stdin)) { line[line_counter].length = strlen(line[line_counter].string); line[line_counter].string[line[line_counter].length-1] = '\0'; if(line[line_counter].length > max_length) { max_length = line[line_counter].length; } line_counter++; } //print the top floor for(i=0; i<max_length+1; i++) printf("*"); printf("\n"); //TODO finish the to the left or to the right edge and bringing them closer left or right alternatively for(i=0; i<line_counter; i++) { printf("*"); j = max_length - line[i].length; //center if(!(j%2)) { for(k=0; k<j/2; k++) printf(" "); printf("%s", line[i].string); for(k=0; k<j/2; k++) printf(" "); } else { if(closing_left) { for(k=0; k<j/2; k++) printf(" "); printf("%s", line[i].string); for(k=0; k<j/2+1; k++) printf(" "); closing_left = 0; } else { for(k=0; k<j/2+1; k++) printf(" "); printf("%s", line[i].string); for(k=0; k<j/2; k++) printf(" "); closing_left = 1; } } printf("*\n"); } //print the bottom floor for(i=0; i<max_length+1; i++) printf("*"); printf("\n"); return 0; }
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor Β«TextpadΒ» decided to introduce this functionality into the fourth release of the product.You are to implement the alignment in the shortest possible time. Good luck!
Format the given text, aligning it center. Frame the whole text with characters Β«*Β» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
C
a017393743ae70a4d8a9d9dc40410653
0a804a254a7b54cdc2fd075bc41c32bb
GNU C
standard output
64 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1269100800
["This is\n\nCodeforces\nBeta\nRound\n5", "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck"]
null
PASSED
1,200
standard input
1 second
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
["************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************", "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"]
#include <stdio.h> #include <string.h> #define MAX_SIZE 1024 typedef struct { char string[MAX_SIZE]; int length; }data; int main(void) { data line[MAX_SIZE]; int max_length = 0, closing_left = 1, line_counter = 0; int i, j, k; i = 0; while(fgets(line[i].string, MAX_SIZE, stdin)) { line[i].length = strlen(line[i].string); if(line[i].length > max_length) { max_length = line[i].length; } i++; line_counter++; } //print the top floor for(i=0; i<max_length+1; i++) printf("*"); printf("\n"); //TODO finish the to the left or to the right edge and bringing them closer left or right alternatively for(i=0; i<line_counter; i++) { printf("*"); j = max_length - line[i].length; //center if(!(j%2)) { for(k=0; k<j/2; k++) printf(" "); for(k=0; k<line[i].length-1; k++) printf("%c", line[i].string[k]); for(k=0; k<j/2; k++) printf(" "); } else { if(closing_left) { for(k=0; k<j/2; k++) printf(" "); for(k=0; k<line[i].length-1; k++) printf("%c", line[i].string[k]); for(k=0; k<j/2+1; k++) printf(" "); closing_left = 0; } else { for(k=0; k<j/2+1; k++) printf(" "); for(k=0; k<line[i].length-1; k++) printf("%c", line[i].string[k]); for(k=0; k<j/2; k++) printf(" "); closing_left = 1; } } printf("*\n"); } //print the bottom floor for(i=0; i<max_length+1; i++) printf("*"); printf("\n"); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
9889a5049732eb6f13a0d03f50d4b4db
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> int main(void) { int x; int s1=0,max = 0,a,b; scanf("%d",&x); while(x--) { scanf("%d %d",&a,&b); s1 = s1 - a + b; if(s1 > max) max = s1; } printf("%d",max); }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
de08c58c3a900fbd40b21b88ad0cd8c5
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int n,a,b,i=1,s=0,p=0,max=0,m; scanf("%d \n",&n); while(i<=n) { scanf("%d %d \n",&a,&b); s+=a; p+=b; m=p-s; if(m>max) max=m; i++; } printf("%d ",max); return(0); }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
98e17c1d5598f5c8d89c3fdbfe3cd0de
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int i,j,n=0,m=0,a[1000],b[1000]; scanf("%d",&i); for(j=0;j<i;j++) { scanf("%d %d",&a[j],&b[j]); n=n-a[j]+b[j]; if(n>m) m=n; } printf("%d",m); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
b02806d16bb5cb96a40e287414b78789
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> #include <stdlib.h> int main(void) { int num, IN, OUT; int sum, max_sum = sum = 0; scanf("%d", &num); for (int i = 0; i < num; i++) { scanf("%d %d", &IN, &OUT); sum += OUT - IN; max_sum = (max_sum < sum ? sum : max_sum); } printf("%d", max_sum); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
9192251d1a3ab76b0793e4efd458eca4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int arr[1000] ; int arr2[1000]; int i ,n , max , temp; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&arr[i]); scanf("%d",&arr2[i]); } max = arr2[0]; temp = max; for(i=1;i<n-1;i++) { temp = arr2[i]+temp-arr[i] ; if(temp>max) max = temp ; } printf("%d",max); }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
48917cdcc0628f2ea882a124495b7168
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> #include <stdlib.h> int main() { int i,j,n,a,b,s=0,x=0; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d %d",&a,&b); x=x+b-a; if(x>s)s=x; } printf("%d",s); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
d41f76a5a2fc6d2cbbae162603675a62
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int i,n,a[1000],b[1000],t,m; scanf("%d", &n); for(i=0;i<n;i++) { scanf( "%d %d",&a[i],&b[i]); } t=b[0]; m=b[0]; for(i=1;i<n;i++) { t=t-a[i]+b[i]; if(t>m) { m=t; } } printf("%d",m); }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
cf2849740f86ed18d8da9cde920bab58
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int n,max=0,i,t=0,l=0; scanf("%d",&n); int a[n],b[n],maxi; for(i=0;i<n;i++) { scanf("%d %d",&a[i],&b[i]); } t=b[0]; l=b[0]; for(i=1;i<n&&a[0]==0&&b[n-1]==0;i++) { maxi=t-a[i]+b[i]; t=maxi; if(l<t) { l=t; } } printf("%d",l); return 0 ; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
29c4feaaf9ee30203ee6c6f4131ef17d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int n,max=0,i,t=0,l=0; scanf("%d",&n); int a[n],b[n],maxi; for(i=0;i<n;i++) { scanf("%d %d",&a[i],&b[i]); } t=b[0]; l=b[0]; for(i=1;i<n&&a[0]==0&&b[n-1]==0;i++) { maxi=t-a[i]+b[i]; t=maxi; if(l<t) { l=t; } } printf("%d",l); return 0 ; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
7cf948cf6c94b14614439de1811da1b1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
// tarm.cpp : Defines the entry point for the console application. // #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int i,c,a,b,sum=0,m=0; scanf("%d",&c); for (i=1;i<=c;i++) { scanf("%d%d",&a,&b); sum=sum-a+b; if (sum>=m)m=sum; } printf("%d",m); return 0 ; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
1c038ce6f8e91e26ff0eaebbe9c2f67d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> int main() { short n; scanf("%hd", &n); int numOnTram; scanf(" %*c %d", &numOnTram); int capacity = numOnTram; for (short i = 1; i < n; i++) { short numGettingOn; short numGettingOff; scanf(" %hd %hd", &numGettingOff, &numGettingOn); numOnTram = numOnTram - numGettingOff + numGettingOn; if (capacity < numOnTram) { capacity = numOnTram; } } printf("%d", capacity); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
4884651e206408b742de0458cf6c9ddf
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> #include <stdlib.h> int main() { static int n,i,j,k,l,c,d; scanf("%d",&n); int arr[n][2]; d=n; for(i=0;i<n;i++) { for(j=0;j<2;j++) { scanf("%d",&arr[i][j]); } }int max,p; max=c=arr[0][1]; k=1; if(n>=2) { for(p=1;p<n;p++) { c=c+(arr[p][1])-(arr[p][0]); if(c>max) max=c; } } printf("%d",max); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
38ea20ae547a5c8900d3bac42b1ebe74
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> #include <stdlib.h> int main() { int n,i,a,b,x,y,max; scanf("%d",&n); x=0; max=0; for (i=1;i<=n;i++){ scanf("%d %d",&a,&b); if (i==n) break; y=x-a+b; max= (max < y) ? y:max; x=y; } printf("%d",max); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
397b06c803c17adcbf856e427bb94245
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include<stdio.h> int main() { int n,sum[100],max=0,k,i,j,count=0; scanf("%d",&n); int str[10001],str1[1001]; for(i=0;i<n;i++) scanf("%d %d",&str[i],&str1[i]); for(i=0;i<n;i++){ max=max-str[i]+str1[i]; if(max>=count)count=max; } printf("%d",count); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
86a62b7ec743625f06bd0e109b1413bc
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> int n[1000][2],stops,i,max = 0,current = 0; int main(){ scanf("%d",&stops); for(i = 0;i < stops;i++){ scanf("%d",&n[i][0]); scanf("%d",&n[i][1]); } for(i = 0;i < stops;i++){ current += n[i][1] - n[i][0]; if(current > max) max = current; } printf("%d",max); return 0; }
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
C
74b90fe9458b147568ac9bd09f219aab
9e66af5f0a71349a433d46ecb4e685fc
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1316098800
["4\n0 3\n2 5\n4 2\n4 0"]
NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
PASSED
800
standard input
2 seconds
The first line contains a single number n (2 ≀ n ≀ 1000) β€” the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≀ ai, bi ≀ 1000) β€” the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0.
["6"]
#include <stdio.h> int main() { int n,i,j; scanf("%d",&n); int a[n][2]; int b[1002]={0},m=0; for(i=0;i<n;i++) { for(j=0;j<2;j++) { scanf("%d",&a[i][j]); } } for(i=0;i+1<n;i++) { b[i]=a[i][1]-a[i+1][0]+a[i+1][1]; a[i+1][1]=b[i]; } for(i=0;i<n;i++) { if(m<b[i]) { m=b[i]; } } for(i=0;i<n;i++) { if(m<a[i][1]) { m=a[i][1]; } } printf("%d",m); return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
f978993e924d4e8c85d3330e490adff8
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
/* http://codeforces.com/contest/816/submission/35318792 (Dukkha) */ #include <limits.h> #include <stdio.h> #define N 100 #define A 500 int main() { static int gg[N][N], rr[N * A], cc[N * A]; int n, m, h, i, j, k, g, d, kr, kc; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &gg[i][j]); k = 0; kr = kc = 0; g = A + 1; for (i = 0; i < n; i++) if (g > gg[i][0]) g = gg[i][0]; for (i = 0; i < n; i++) { d = gg[i][0] - g; if (d == 0) continue; for (j = 0; j < m; j++) if ((gg[i][j] -= d) < 0) { printf("-1\n"); return 0; } k += d; while (d-- > 0) rr[kr++] = i + 1; } g = A + 1; for (j = 0; j < m; j++) if (g > gg[0][j]) g = gg[0][j]; for (j = 0; j < m; j++) { d = gg[0][j] - g; if (d == 0) continue; for (i = 0; i < n; i++) if ((gg[i][j] -= d) < 0) { printf("-1\n"); return 0; } k += d; while (d-- > 0) cc[kc++] = j + 1; } g = gg[0][0]; for (i = 0; i < n; i++) for (j = 0; j < m; j++) if (gg[i][j] != g) { printf("-1\n"); return 0; } if (n <= m) { k += n * g; for (i = 0; i < n; i++) for (h = 0; h < g; h++) rr[kr++] = i + 1; } else { k += m * g; for (j = 0; j < m; j++) for (h = 0; h < g; h++) cc[kc++] = j + 1; } printf("%d\n", k); for (h = 0; h < kr; h++) printf("row %d\n", rr[h]); for (h = 0; h < kc; h++) printf("col %d\n", cc[h]); return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
4b60d8c337952a136ec5b73fd8626fa3
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include<stdio.h> int game[101][101], n, m, num[5000001]; char ch[5000001]; int find_min(int row, int col){ int j,min=99999; if(row!=-1){ for(j=0;j<n;j++) if(min > game[row][j]) min = game[row][j]; return min; } for(j=0;j<m;j++) if(min > game[j][col]) min = game[j][col]; return min; } int solve(){ int ans = 0,j,k,count=0; if(n>m){ for(j=0;j<m;j++){ int min = find_min(j, -1); ans += min; if(min > 0){ for(k=0;k<min;k++){ ch[count++] = 'r'; num[count-1] = j+1; } } for(k=0;k<n;k++) game[j][k] -= min; } for(j=0;j<n;j++){ int min = find_min(-1, j); ans += min; if(min > 0){ for(k=0; k<min; k++){ ch[count] = 'c'; num[count++] = j+1; } } for(k=0;k<m;k++) game[k][j] -= min; } } else{ for(j=0;j<n;j++){ int min = find_min(-1, j); ans += min; if(min > 0){ for(k=0; k<min; k++){ ch[count] = 'c'; num[count++] = j+1; } } for(k=0;k<m;k++) game[k][j] -= min; } for(j=0;j<m;j++){ int min = find_min(j, -1); ans += min; if(min > 0){ for(k=0;k<min;k++){ ch[count++] = 'r'; num[count-1] = j+1; } } for(k=0;k<n;k++) game[j][k] -= min; } } for(j=0;j<m;j++) for(k=0;k<n;k++) if(game[j][k]!=0) return -1; return ans; } int main(){ scanf("%d %d",&m ,&n); int j,k; for(j=0;j<m;j++) for(k=0;k<n;k++) scanf("%d",&game[j][k]); int ans = solve(); if(ans==-1){ printf("-1\n"); return 0; } printf("%d\n",ans); for(j=0;j<ans;j++){ if(ch[j] == 'r') printf("row %d\n",num[j]); else printf("col %d\n",num[j]); } return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
595a77131e34721c676932e30d0b29ee
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <math.h> #define MOD 1000000007 #define ll long long int cmpfunc(const void *a, const void *b){ return (*(int*)a - *(int*)b); } int main(void){ int n,m,i,j,steps; scanf("%d %d",&n,&m); int a[n+1][m+1]; int c[n+1][m+1]; int is_zero = 0; int row,col; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&a[i][j]); c[i][j]=a[i][j]; if(a[i][j]==0){ is_zero=1; row=i; col=j; } } } if(is_zero){ steps=0; for(j=1;j<=m;j++){ //col j delete by a[row][j] for(i=1;i<=n;i++){ c[i][j]-=a[row][j]; if(c[i][j]<0){ printf("-1\n"); return 0; } } steps+=a[row][j]; } for(i=1;i<=n;i++){ for(j=2;j<=m;j++){ c[i][j]-=c[i][1]; if(c[i][j]!=0){ printf("-1\n"); return 0; } } steps+=c[i][1]; } printf("%d\n",steps); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ c[i][j]=a[i][j]; } } for(j=1;j<=m;j++){ //col j delete by a[row][j] for(int k=0;k<a[row][j];k++){ printf("col %d\n",j); } for(i=1;i<=n;i++){ c[i][j]-=a[row][j]; } } for(i=1;i<=n;i++){ if(i==row) continue; for(int k=0;k<c[i][1];k++){ printf("row %d\n",i); } } return 0; } if(n<=m){ steps=0; int min_row1=MOD; for(i=1;i<=m;i++){ if(a[1][i]<min_row1) { min_row1=a[1][i]; row=1; col=i; } } steps+=a[row][col]; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ c[i][j]=a[i][j]; } } for(i=1;i<=m;i++){ c[1][i]-=steps; } int step1=steps; //printf("row=%d col=%d\n",row,col); for(j=1;j<=m;j++){ //col j delete by a[row][j] for(i=1;i<=n;i++){ c[i][j]-=a[row][j]-step1; if(c[i][j]<0){ printf("-1\n"); return 0; } } steps+=a[row][j]-step1; } for(i=1;i<=n;i++){ for(j=2;j<=m;j++){ c[i][j]-=c[i][1]; if(c[i][j]!=0){ printf("-1\n"); return 0; } } steps+=c[i][1]; } printf("%d\n",steps); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ c[i][j]=a[i][j]; } } for(i=1;i<=m;i++){ c[1][i]-=step1; } for(i=0;i<step1;i++) printf("row 1\n"); for(j=1;j<=m;j++){ //col j delete by a[row][j]-step1 for(int k=0;k<a[row][j]-step1;k++){ printf("col %d\n",j); } for(i=1;i<=n;i++){ c[i][j]-=a[row][j]-step1; } } for(i=1;i<=n;i++){ if(i==row) continue; for(int k=0;k<c[i][1];k++){ printf("row %d\n",i); } } }else{ //row<->col m<->n //printf("revervev\n"); steps=0; int min_col1=MOD; for(i=1;i<=n;i++){ if(a[i][1]<min_col1) { min_col1=a[i][1]; row=i; col=1; } } steps+=a[row][col]; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ c[i][j]=a[i][j]; } } for(i=1;i<=n;i++){ c[i][1]-=steps; } int step1=steps; //printf("row=%d col=%d\n",row,col); for(j=1;j<=n;j++){ //row j delete by a[j][col] for(i=1;i<=m;i++){ c[j][i]-=a[j][col]-step1; if(c[j][i]<0){ printf("-1\n"); return 0; } } steps+=a[j][col]-step1; } for(i=1;i<=m;i++){ for(j=2;j<=n;j++){ c[j][i]-=c[1][i]; if(c[j][i]!=0){ printf("-1\n"); return 0; } } steps+=c[1][i]; } printf("%d\n",steps); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ c[i][j]=a[i][j]; } } for(i=1;i<=n;i++){ c[i][1]-=step1; } for(i=0;i<step1;i++) printf("col 1\n"); for(j=1;j<=n;j++){ //col j delete by a[row][j]-step1 for(int k=0;k<a[j][col]-step1;k++){ printf("row %d\n",j); } for(i=1;i<=m;i++){ c[j][i]-=a[j][col]-step1; } } for(i=1;i<=m;i++){ if(i==col) continue; for(int k=0;k<c[1][i];k++){ printf("col %d\n",i); } } } return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
d7d72e9d91eba0d4e7f2ae878e98ad8f
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include<stdio.h> int a[101][101],b[101][101]; int main() { int n,m,i,j,min=1000,row[102],col[103],count=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { min=1000; for(j=0;j<m;j++) { scanf("%d",&a[i][j]); b[i][j]=a[i][j]; if(a[i][j]<min) { min=a[i][j]; row[i]=min; } } if(row[i]>=0) count+=row[i]; for(j=0;j<m;j++) a[i][j]-=row[i]; } min=1000; for(j=0;j<m;j++) { min=1000; for(i=0;i<n;i++) { if(a[i][j]<min) { min=a[i][j]; col[j]=min; } } if(col[j]>=0) count+=col[j]; for(i=0;i<n;i++) a[i][j]-=col[j]; } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(a[i][j]!=0) { printf("-1\n"); return 0; } } } int ii,jj,row1[102],col1[103],count1=0; for(jj=0;jj<m;jj++) { min=1000; for(ii=0;ii<n;ii++) { if(b[ii][jj]<min) { min=b[ii][jj]; col1[jj]=min; } } if(col1[jj]>=0) count1+=col1[jj]; for(ii=0;ii<n;ii++) b[ii][jj]-=col1[jj]; } for(ii=0;ii<n;ii++) { min=1000; for(jj=0;jj<m;jj++) { if(b[ii][jj]<min) { min=b[ii][jj]; row1[ii]=min; } } if(row1[ii]>=0) count1+=row1[ii]; for(jj=0;jj<m;jj++) b[ii][jj]-=row1[ii]; } if(count<count1) { printf("%d\n",count); for(i=0;i<n;i++) { if(row[i]!=0) { while(row[i]--) printf("row %d\n",i+1); } } for(i=0;i<m;i++) { if(col[i]!=0) { while(col[i]--) printf("col %d\n",i+1); } } } else if(count>=count1) { printf("%d\n",count1); for(i=0;i<n;i++) { if(row1[i]!=0) { while(row1[i]--) printf("row %d\n",i+1); } } for(i=0;i<m;i++) { if(col1[i]!=0) { while(col1[i]--) printf("col %d\n",i+1); } } } return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
e4932e30e2eec0aaa02939087b408bcd
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include<stdio.h> #include<string.h> #include<limits.h> int g[102][102]; int g2[102][102]; int my[5000001][2]; int my2[5000001][2]; int main() { int n,m,i,j,k,ans=0,cc=0,abc=-1; int min=INT_MAX; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&g[i][j]); g2[i][j]=g[i][j]; } } for(i=0;i<n;i++) { min=INT_MAX; for(j=0;j<m;j++) { if(g[i][j]<min) min=g[i][j]; } ans+=min; for(j=0;j<m;j++) { g[i][j]-=min; } for(j=0;j<min;j++) { //printf("row %d\n",i+1); my[cc][0]=i+1; my[cc++][1]=1; //row } } for(i=0;i<m;i++) { min=INT_MAX; for(j=0;j<n;j++) { if(g[j][i]<min) min=g[j][i]; } ans+=min; for(j=0;j<n;j++) { g[j][i]-=min; } for(j=0;j<min;j++) { //printf("col %d\n",i+1); my[cc][0]=i+1; my[cc++][1]=2; //col } } int f=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(g[i][j]!=0) { f=1; break; } } } int ans2=0; cc=0; for(i=0;i<m;i++) { min=INT_MAX; for(j=0;j<n;j++) { if(g2[j][i]<min) min=g2[j][i]; } ans2+=min; for(j=0;j<n;j++) { g2[j][i]-=min; } for(j=0;j<min;j++) { //printf("col %d\n",i+1); my2[cc][0]=i+1; my2[cc++][1]=2; //col } } for(i=0;i<n;i++) { min=INT_MAX; for(j=0;j<m;j++) { if(g2[i][j]<min) min=g2[i][j]; } ans2+=min; for(j=0;j<m;j++) { g2[i][j]-=min; } for(j=0;j<min;j++) { //printf("row %d\n",i+1); my2[cc][0]=i+1; my2[cc++][1]=1; //row } } int f2=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(g2[i][j]!=0) { f2=1; break; } } } int zz,yy=0; if(f==0 & f2==0) { if(ans<ans2) { zz=ans; yy=1; } else { zz=ans2; yy=2; } printf("%d\n",zz); if(yy==1) { for(i=0;i<zz;i++) { if(my[i][1]==1) printf("row %d\n",my[i][0]); else if(my[i][1]==2) printf("col %d\n",my[i][0]); } } else { for(i=0;i<zz;i++) { if(my2[i][1]==1) printf("row %d\n",my2[i][0]); else if(my2[i][1]==2) printf("col %d\n",my2[i][0]); } } } else if(f==0) { for(i=0;i<ans;i++) { if(my[i][1]==1) printf("row %d\n",my[i][0]); else if(my[i][1]==2) printf("col %d\n",my[i][0]); } } else if(f2==0) { for(i=0;i<ans2;i++) { if(my2[i][1]==1) printf("row %d\n",my2[i][0]); else if(my2[i][1]==2) printf("col %d\n",my2[i][0]); } } else printf("-1\n"); return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
6f8ce68680308e82f91ad01dd2e7a293
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include <stdio.h> int check(int** A, int n, int m){ int flag = 1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++){ if (A[i*m + j] != 0) flag = 0; } return flag; } int main(){ int n,m; scanf("%d%d", &n, &m); int A[n][m]; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++) scanf("%d", &A[i][j]); } int oper[501][3]; int count = 0; if (n > m){ int max = 501; for (int i = 0; i < m; i++){ max = 501; for (int j = 0; j < n; j++) if (A[j][i] < max) max = A[j][i]; for (int j = 0; j < n; j++) A[j][i] -= max; if (max > 0){ oper[count][0] = 1; oper[count][1] = i; oper[count][2] = max; count++; } } for (int j = 0; j < n; j++){ max = 501; for (int i = 0; i < m; i++) if (A[j][i] < max) max = A[j][i]; for (int i= 0; i < m; i++) A[j][i] -= max; if (max > 0){ oper[count][0] = 2; oper[count][1] = j; oper[count][2] = max; count++; } } if (!check(A, n, m)) printf("-1"); else{ int k = 0; for (int i = 0; i < count; i++){ for (int j = 0; j < oper[i][2]; j++) k++; } printf("%d\n", k); for (int i = 0; i < count; i++){ if (oper[i][0] == 2){ for (int j = 0; j < oper[i][2]; j++) printf("row %d\n", oper[i][1] + 1); } else{ for (int j = 0; j < oper[i][2]; j++) printf("col %d\n", oper[i][1] + 1); } } } return 0; } int max = 501; for (int j = 0; j < n; j++){ max = 501; for (int i = 0; i < m; i++) if (A[j][i] < max) max = A[j][i]; for (int i= 0; i < m; i++) A[j][i] -= max; if (max > 0){ oper[count][0] = 2; oper[count][1] = j; oper[count][2] = max; count++; } } for (int i = 0; i < m; i++){ max = 501; for (int j = 0; j < n; j++) if (A[j][i] < max) max = A[j][i]; for (int j = 0; j < n; j++) A[j][i] -= max; if (max > 0){ oper[count][0] = 1; oper[count][1] = i; oper[count][2] = max; count++; } } if (!check(A, n, m)) printf("-1"); else{ int k = 0; for (int i = 0; i < count; i++){ for (int j = 0; j < oper[i][2]; j++) k++; } printf("%d\n", k); for (int i = 0; i < count; i++){ if (oper[i][0] == 2){ for (int j = 0; j < oper[i][2]; j++) printf("row %d\n", oper[i][1] + 1); } else{ for (int j = 0; j < oper[i][2]; j++) printf("col %d\n", oper[i][1] + 1); } } } }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
315cfc9cb9c929f1b2b7798e11dbdba8
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include <stdio.h> int main () { int a,b,c,x,y,z,l,m,n; int min ; int input[500][500], output[500][500] ; int minr[500]; int minc[500]; int sumr = 0 , sumc = 0 ; int flag = 0 ; scanf ("%d %d",&n,&m); for (a=1 ;a<= n;a++) { for (b=1 ;b<=m;b++) { scanf ("%d",&input[a][b]); } } for (a=1 ; a<=n ;a++) { for (b=1 ;b<=m ;b++) { output[a][b] = input[a][b] ; } } if (n<=m) { for (a=1 ;a<=n;a++) { min = 10000; for (b=1; b<=m;b++) { if (input[a][b] <= min) { min = input[a][b] ; } } minr[a] = min ; for (z=1;z<=m;z++) { output[a][z] = output[a][z] - minr[a] ; } } for (a=1 ;a<=m ;a++) { min = 10000 ; for (b=1 ;b<=n ;b++) { if (output[b][a] <=min) { min = output[b][a] ; } } minc[a] = min ; } } else { for (b=1 ;b<=m;b++) { min = 10000; for (a=1; a<=n;a++) { if (input[a][b] <= min) { min = input[a][b] ; } } minc[b] = min ; for (z=1;z<=n;z++) { output[z][b] = output[z][b] - minc[b] ; } } for (a=1 ;a<=n ;a++) { min = 10000 ; for (b=1 ;b<=m ;b++) { if (output[a][b] <=min) { min = output[a][b] ; } } minr[a] = min ; } } for (a=1 ;a<=n;a++) { for (b=1 ;b<=m;b++) { if (input[a][b] != (minr[a]+minc[b]) ) { printf ("-1\n"); flag = - 1 ; break ; } } if (flag == -1 ) { break ; } } for (l = 1 ;l<=n ;l++) { sumr = sumr + minr[l] ; } for (l=1 ;l<=m ;l++) { sumc = sumc + minc[l] ; } if (flag == 0) { printf ("%d\n",sumr+sumc) ; for (x=1 ;x<=n;x++) { for (y=1 ;y<=minr[x] ;y++) { printf ("row %d\n",x); } } for (x=1 ;x<=m;x++) { for (y=1 ; y<=minc[x] ; y++) { printf ("col %d\n",x); } } } return 0 ; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
d3fca79333bdd74a6747fa9c5180447f
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include<stdio.h> #include<string.h> int map[101][101]; int row[50001], col[50001]; int main() { int m, n, row1 = 0, col1 = 0, sum = 0; scanf("%d %d", &n, &m); memset(row, 0, sizeof(row)); memset(col, 0, sizeof(col)); for(int i=1;i<=n;i++) for (int j = 1; j <= m; j++) { scanf("%d", &map[i][j]); sum += map[i][j]; } if (m < n) goto loop ; loop2:; for (int i = 1; i <= n; ) { int flag = 1; for (int j = 1; j <= m; j++) { if (map[i][j] < 1) { flag = 0; break; } } if (flag == 1) { for (int j = 1; j <= m; j++) map[i][j]--; row[row1] = i; row1++; sum -= m; } else i++; } if (m < n) goto loop3; loop:; for (int i = 1; i <= m; ) { int flag = 1; for (int j = 1; j <= n; j++) { if (map[j][i] < 1) { flag = 0; break; } } if (flag == 1) { for (int j = 1; j <= n; j++) map[j][i]--; col[col1] = i; col1++; sum -= n; } else i++; } if (m < n) goto loop2; loop3:; if (sum != 0) printf("-1\n"); else { printf("%d\n", col1 + row1); for (int i = row1 - 1; i >= 0; i--) printf("row %d\n", row[i]); for (int i = col1 - 1; i >= 0; i--) printf("col %d\n", col[i]); } return 0; }
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: row x, (1 ≀ x ≀ n) describing a move of the form "choose the x-th row". col x, (1 ≀ x ≀ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them.
C
b19ab2db46484f0c9b49cf261502bf64
2f6a1fb1aada9fbe94956585c65b85d9
GNU C
standard output
512 megabytes
train_002.jsonl
[ "implementation", "greedy", "brute force" ]
1497710100
["3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "3 3\n0 0 0\n0 1 0\n0 0 0", "3 3\n1 1 1\n1 1 1\n1 1 1"]
NoteIn the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
PASSED
1,700
standard input
2 seconds
The first line of input contains two integers, n and m (1 ≀ n, m ≀ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≀ gi, j ≀ 500).
["4\nrow 1\nrow 1\ncol 4\nrow 3", "-1", "3\nrow 1\nrow 2\nrow 3"]
#include<stdio.h> int main() { long long row, col, p=0,arr[105][105], x=1, y=1, i, j, cnt, final=2100000000, k, ver[105], hor[105], VER[105], HOR[105], flag=0; scanf("%lld %lld", &row, &col); for(i=1; i<=row; i++) for(j=1; j<=col; j++) scanf("%lld",&arr[i][j]); for(i=0; i<=arr[1][1]; i++){ flag = 0; cnt = 0; for(j=1; j<=row; j++){ ver[j] = arr[j][1] - (arr[1][1] - i); cnt += ver[j]; if(ver[j]< 0){ flag = 1; break; } } for(j=1; j<=col; j++){ hor[j] = arr[1][j] - i; cnt += hor[j]; if(hor[j]< 0){ flag = 1; break; } } if((flag != 1)&&(cnt < final)){ for(j=1; j<=row; j++){ for(k=1; k<=col; k++){ if(arr[j][k] != ver[j] + hor[k]) flag = 1; } } if(flag != 1){ final = cnt; for(j=1; j<=row; j++) VER[j] = ver[j]; for(j=1; j<=col; j++) HOR[j] = hor[j]; p=5; } } } if(flag == 1 && p == 0) printf("-1\n"); else{ printf("%lld\n",final); for(j=1; j<=row; ){ if(VER[j] == 0) j++; else{ printf("row %lld\n",j); VER[j]--; } } for(j=1; j<=col; ){ if(HOR[j] == 0) j++; else{ printf("col %lld\n",j); HOR[j]--; } } } return 0; }
You're given a tree with $$$n$$$ vertices.Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
Output a single integer $$$k$$$ β€” the maximum number of edges that can be removed to leave all connected components with even size, or $$$-1$$$ if it is impossible to remove edges in order to satisfy this property.
C
711896281f4beff55a8826771eeccb81
1b010bf12442678604477567490d954c
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "graphs", "dfs and similar", "trees" ]
1526574900
["4\n2 4\n4 1\n3 1", "3\n1 2\n1 3", "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5", "2\n1 2"]
NoteIn the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each.In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.
PASSED
1,500
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) denoting the size of the tree. The next $$$n - 1$$$ lines contain two integers $$$u$$$, $$$v$$$ ($$$1 \le u, v \le n$$$) each, describing the vertices connected by the $$$i$$$-th edge. It's guaranteed that the given edges form a tree.
["1", "-1", "4", "0"]
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 100007 struct q{ int l,r; }a[N<<1]; struct r{ int l,r; }r__[N]; int p[N],n,l_; int first[N],next[N<<1]; int r_; int find(int i,int j){ int k,x; x=1; for(k=first[i];k!=-1;k=next[k]){ if(p[a[k].r]==-1){ p[a[k].r]=i; x+=find(a[k].r,j+x); } } r__[i].l=j; r__[i].r=j+x; if(x%2==0){ r_++; } return x; } void cat(){ int i; for(i=0;i<N;i++){ first[i]=-1; } memset(next,0,sizeof(next)); for(i=l_-1;i>=0;i--){ next[i]=first[a[i].l]; first[a[i].l]=i; } for(i=0;i<n;i++){ p[i]=-1; } r_=-1; p[0]=0; find(0,0); printf("%d\n",r_); } void run(){ int i,l,r; while(scanf("%d",&n)!=EOF){ l_=0; for(i=0;i<n-1;i++){ scanf("%d%d",&l,&r); a[l_].l=l-1; a[l_].r=r-1; a[l_+1].l=r-1; a[l_+1].r=l-1; l_+=2; } if(n%2==1){ printf("-1\n"); continue; } cat(); } } main(){ run(); return 0; }
You're given a tree with $$$n$$$ vertices.Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
Output a single integer $$$k$$$ β€” the maximum number of edges that can be removed to leave all connected components with even size, or $$$-1$$$ if it is impossible to remove edges in order to satisfy this property.
C
711896281f4beff55a8826771eeccb81
75b6851296cba2f5325c42a4dd438aab
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "graphs", "dfs and similar", "trees" ]
1526574900
["4\n2 4\n4 1\n3 1", "3\n1 2\n1 3", "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5", "2\n1 2"]
NoteIn the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each.In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.
PASSED
1,500
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) denoting the size of the tree. The next $$$n - 1$$$ lines contain two integers $$$u$$$, $$$v$$$ ($$$1 \le u, v \le n$$$) each, describing the vertices connected by the $$$i$$$-th edge. It's guaranteed that the given edges form a tree.
["1", "-1", "4", "0"]
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <malloc.h> #include <memory.h> int n,s[100005],f[100005],a[100005],b[100005],*g[100005],i,j,ans,r[100005]; int dfs(int x) { int i; for (i=1,s[x]=1;i<=r[x];i++) if (!f[g[x][i]]) { f[g[x][i]]=1; s[x]+=dfs(g[x][i]); } if (s[x]%2==0) ans++; return s[x]; } int main() { memset(r,0,sizeof(r)); memset(f,0,sizeof(f)); scanf("%d",&n); if (n&1) { printf("-1\n"); exit(0); } for (i=1;i<n;i++) { scanf("%d %d",&a[i],&b[i]); r[a[i]]++; r[b[i]]++; } for (i=1;i<=n;i++) g[i]=(int *) malloc((r[i]+1)*sizeof(int)); memset(r,0,sizeof(r)); for (i=1;i<n;i++) { g[a[i]][++r[a[i]]]=b[i]; g[b[i]][++r[b[i]]]=a[i]; } for (i=s[1]=f[1]=1,ans=0;i<=r[1];i++) if (!f[g[1][i]]) { f[g[1][i]]=1; s[1]+=dfs(g[1][i]); } printf("%d\n",ans); return 0; }
You're given a tree with $$$n$$$ vertices.Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
Output a single integer $$$k$$$ β€” the maximum number of edges that can be removed to leave all connected components with even size, or $$$-1$$$ if it is impossible to remove edges in order to satisfy this property.
C
711896281f4beff55a8826771eeccb81
604a936ca6b0027a3df7bdab3e2fe549
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "graphs", "dfs and similar", "trees" ]
1526574900
["4\n2 4\n4 1\n3 1", "3\n1 2\n1 3", "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5", "2\n1 2"]
NoteIn the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each.In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.
PASSED
1,500
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) denoting the size of the tree. The next $$$n - 1$$$ lines contain two integers $$$u$$$, $$$v$$$ ($$$1 \le u, v \le n$$$) each, describing the vertices connected by the $$$i$$$-th edge. It's guaranteed that the given edges form a tree.
["1", "-1", "4", "0"]
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> typedef struct node{ int val; struct node * next; }node; void insert(int a,int b,node *head) { node* temp=(node *)malloc(sizeof(node)*1); temp->val=b; temp->next=head[a].next; head[a].next=temp; } void dfs(int i,node* head,int *hic,int *ar) { node *temp1 = head[i].next; while(temp1!=NULL) { if(hic[temp1->val]!=1) { hic[temp1->val]=1; dfs(temp1->val,head,hic,ar); //printf("Yo %d %d %d %d\n",i,ar[i],temp1->val,ar[temp1->val]); //hic[temp1->val]=1; ar[i]+=ar[temp1->val]; } temp1=temp1->next; } ar[i]+=1; return; } int main() { int n,i,a,b,count; scanf("%d",&n); int hic[n+1]; node *head=(node *)malloc(sizeof(node)*(n+1)); for(i=1;i<=n;i++) { hic[i]=0; head[i].val = i; head[i].next=NULL; } for(i=0;i<(n-1);i++) { scanf("%d %d",&a,&b); insert(a,b,head); insert(b,a,head); } if(n%2==1) printf("-1\n"); else { int ar[n+1]; count=0; for(i=0;i<=n;i++) ar[i]=0; hic[1]=1; dfs(1,head,hic,ar); for(i=1;i<=n;i++) { //printf("%d %d\n",i,ar[i]); if(ar[i]%2==0) count+=1; } printf("%d\n",count-1); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
878a1a6375aa7a52437737248f49be31
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); long a[n]; for(int i=0;i<n;i++){ scanf("%ld",&a[i]); } long bp[n],bn[n],cp=-1,cn=-1;; long long cost=0; for(int i=n-1;i>=0;i--){ if(a[i]<0){ cn++; bn[cn]=a[i]; } else if(a[i]>0){ if(cn>=0){ for(int j=cn;j>=0;j--){ if(a[i]+bn[j]<0){ // a[i]=0; bn[j]=bn[j]+a[i]; // printf("%d",bn[j]); a[i]=0; break; } else if(a[i]+bn[j]==0){ a[i]=0; bn[j]=0; cn--; break; } else{ a[i]+=bn[j]; cn--; } } if(a[i]>0){ cp++; bp[cp]=a[i]; } } else{ cp++; bp[cp]=a[i]; } } } for(int i=0;i<=cp;i++){ // printf("%d ",bp[i]); cost+=bp[i]; } for(int i=0;i<=cn;i++){ //printf("%d ",bn[i]); cost+=(-bn[i]); } if(cost%2==0){ printf("%lld\n",cost/2); } else printf("%lld\n",cost/2+1); } }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
660d6c54f66f81eb0f80a78b628692d7
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> int main() { // freopen("/home/shadhin/Desktop/code/IO/input.txt", "r", stdin); // freopen("/home/shadhin/Desktop/code/IO/output.txt", "w", stdout); int n, i, x, t; long long int sum; scanf("%d", &t); while(t--) { scanf("%d", &n); sum=0; for(i=0;i<n;i++) { scanf("%d", &x); sum+=x; if(sum<0) sum=0; } printf("%lld\n", sum); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
44b9ddebe2a95680ea5307f744e300fc
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> #include <stdlib.h> int main() { int t; scanf("%d", &t); for(int i = 0; i < t; i++) { int n; scanf("%d", &n); long long A[n]; for(int j=0; j < n; j++) scanf("%lld", &A[j]); // CODE FROM HERE long long fc = 0; long long res = 0; for(int k=0; k < n; k++) { if(A[k] >= 0) fc += A[k]; else if(fc > -A[k]) fc += A[k]; else { res += -(A[k] + fc); fc = 0; } } printf("%lld\n", res); // CODE TILL HERE } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
a93d3779e618220735019f675d568ced
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> // #define min(a,b) (a<b)?a:b ; #define min(a,b) ((a) < (b) ? (a) : (b)) int main() { int T=1 ; scanf("%d",&T); while(T--) { int n ; scanf("%d",&n) ; long long int a[n] ; for(int i=0 ; i<n ; i++) scanf("%lld",&a[i]) ; long long int c=0 , s=0; for(int i=0 ; i<n ; i++) { s+=a[i] ; c = min(c,s) ; } // printf("%ld ",s) ; // if(s>0) c+=s ; printf("%lld\n",-c) ; } return 0 ; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
e826604814a7e4769a8d0f3033517e61
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> #include<stdlib.h> //int size; int top=-1; int stack[100000]; int push(int ); int pop(); //void operation(); //function declaration for function operation which is used to determine whether to perform push,pop,peek or display int main() { int t,i,n,j; scanf("%d",&t); int a[100000]; long long int ans[t]; for(i=0;i<t;i++) { ans[i]=0; scanf("%d",&n); for(j=0;j<n;j++) { scanf("%d",&a[j]); again:; if(a[j]<0) { if(stack[top]>0) { if(stack[top]+a[j]<0) { a[j]=a[j]+pop(); //j--; goto again; } else if(stack[top]+a[j]>0) { push(pop()+a[j]); } else { pop(); } } } else if(a[j]>0) { push(a[j]); } } for(;top>-1;) { // printf("%d",ans[i]); ans[i]=ans[i]+pop(); //printf("%d",ans[i]); } } for(i=0;i<t;i++) { printf("%lld\n",ans[i]); } return 0; } int push(int e) { // char e; //printf("Which element would you like to push?"); //scanf(" %c",&e); // if(top==size-1) // { // printf("Stack Overflow"); // } // else // { top=top+1; stack[top]=e; return 0; // } // operation(); } int pop() { /*if(top==-1) { printf("Underflow"); } else {*/ //printf("Popped item is %c\n",stack[top]); top--; return stack[top+1]; //top=top-1; // operation(); // } } /*7 4 -3 5 -3 1 2 1 -1 4 -3 2 -3 4 4 -1 1 1 -1 7 -5 7 -6 -4 17 -13 4 6 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1 0 */
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
714b54ef682c28cb3e6e5b420b0ad69c
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> long long _abs(long long a){ if(a<0){ return -a; } return a; } int main(void){ int i, T, N, s, e; long long cnt, arr[100000]; scanf("%d", &T); while(T--){ scanf("%d", &N); for(i=0; i<N; ++i){ scanf("%lld", arr+i); } if(N==1){ printf("0\n"); continue; } s=0; e=-1; while(s<N){ if(arr[s]<=0){ ++s; } else{ if(e==-1 || e<=s){ e=s+1; } if(e>=N){ break; } while(arr[s] && e<N){ if(arr[e]<0){ if(_abs(arr[s])<_abs(arr[e])){ arr[e]+=arr[s]; arr[s]=0; } else if(_abs(arr[s])>_abs(arr[e])){ arr[s]+=arr[e]; arr[e]=0; ++e; } else{ arr[s]=0; arr[e]=0; } } else{ ++e; } } } } cnt=0; s=0; e=1; while(s<N && e<N){ if(arr[s]==0){ ++s; } if(arr[e]==0){ ++e; } if(arr[s]<0 && arr[e]>0){ if(_abs(arr[s])<_abs(arr[e])){ if(s<=e){ cnt+=_abs(arr[s]); } arr[e]-=_abs(arr[s]); arr[s]=0; ++s; } else if(_abs(arr[s])>_abs(arr[e])){ if(s<=e){ cnt+=_abs(arr[e]); } arr[s]+=_abs(arr[e]); arr[e]=0; ++e; } else{ if(s<=e){ cnt+=_abs(arr[s]); } arr[s]=0; arr[e]=0; ++s; ++e; } } else if(arr[s]<0 && arr[e]<0){ ++e; continue; } else if(arr[s]>0 && arr[e]<0){ if(_abs(arr[s])>_abs(arr[e])){ if(s>=e){ cnt+=_abs(arr[e]); } arr[s]-=_abs(arr[e]); arr[e]=0; ++e; } else if(_abs(arr[s])<_abs(arr[e])){ if(s>=e){ cnt+=_abs(arr[s]); } arr[e]+=_abs(arr[s]); arr[s]=0; ++s; } else{ if(s>=e){ cnt+=_abs(arr[s]); } arr[s]=0; arr[e]=0; ++s; ++e; } } else if(arr[s]>0 && arr[e]>0){ ++e; continue; } } printf("%lld\n", cnt); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
64d345e743c33c2f128d5adcba700f59
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> #include <stdlib.h> int main (void) { int t; scanf ("%i", &t); while (t--) { int n; scanf ("%i", &n); long *a = malloc (n * sizeof(long)); long *p = a; for (; p < a+n; p++) scanf ("%li", p); long long credit = 0; long long deficit = 0; for (p -= 1; p > a; p--) { credit -= *p; if (credit < 0) { deficit -= credit; credit = 0; } } printf ("%lli\n", deficit); } }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
df4b11928341733b120f1d4d00e8cef6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { long long int i,j,m,n,t; scanf("%lld", &t); while(t--){ scanf("%lld", &n); long long int a[n],neg=0,pos=0; for(i=0;i<n;i++){ scanf("%lld", &a[i]); } for(i=0;i<n;i++){ if(abs(a[i])>pos&&a[i]<0){ neg+=pos+a[i]; pos=0; } else if(abs(a[i])<=pos&&a[i]<0){ pos=pos+a[i]; } else if(a[i]>=0){ pos+=a[i]; } } printf("%lld\n", pos); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
dd524f8619dc7de1137b36d2f90bce5e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> void main() { int t; scanf("%i",&t); while(t--) { int n; scanf("%i",&n); long long int a[n]; for(int i=0;i<n;i++) scanf("%lli",&a[i]); long long int sum=0; for(int i=0;i<n;i++) { //printf("%lli ",sum); if(a[i]>0) { sum+=a[i]; continue; } else if(a[i]<0) { if(sum>=(-a[i])) { sum+=a[i]; } else sum=0; } } printf("%lli\n",sum); } }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
d8dcca9a3c848bdca697da8325d9991e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> long long min(long long a,long long b){ if(a>b)return b; else return a; } long long max(long long a,long long b){ if(a>b)return a; else return b; } int main(int argc, char *argv[]) { int tc; scanf("%d",&tc); while(tc--){ long long n,i,sum=0,d,ss; scanf("%lld",&n); long long a[n+6],pref[n+6]; for(i=1;i<=n;i++){ scanf("%lld",&a[i]); } for(i=1;i<=n;i++){ if(a[i]<0){ d=a[i]*(-1); a[i]=min(sum-d,0); sum=max(sum-d,0); if(sum<=0)sum=0; } else{ sum+=a[i]; } } ss=0; for(i=1;i<=n;i++) if(a[i]<0){ ss+=a[i]; // printf("%lld\n",a[i]); } printf("%lld\n",ss*(-1)); } }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
5e38226fd56b5462186a233fc2b87160
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> void count_coins(); int t,a,n,i,j,k,l; long long coins[5000], array[100000]; int main(){ scanf("%d", &t); for(i = 0; i < t; i++){ scanf("%d", &n); for(j = 0; j < n; j++){ scanf("%lld", &array[j]); } for(k = 0; k < n; k++){ if(array[k] < 0){ coins[i] -= array[k]; } else{ array[k+1] += array[k]; } } } for(l = 0; l < t; l++){ printf("%lld\n", coins[l]); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
e6b68f57aaa088407651482aa5b5f5dc
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> int main() { int n, i, x, t; long long int sum; scanf("%d", &t); while(t--) { scanf("%d", &n); sum=0; for(i=0; i<n; i++) { scanf("%d", &x); sum+=x; if(sum<0) sum=0; } printf("%lld\n", sum); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
fbd0b4951e2bce160937a9a1d3e1f840
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> int main() { int n,t,i; long long int sum,sum2; scanf("%d",&t); for(;t>0;t--) { scanf("%d",&n); int a[n]; sum=sum2=0; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0 && sum2==0) sum=sum+a[i]; else if(a[i]<0 && sum2!=0) { if(sum2>(-1*a[i])) sum2=sum2+a[i]; else { sum=sum+(a[i]+sum2); sum2=0; } } else { sum2=sum2+a[i]; } //printf("%d %d\n",sum,sum2); } // if(sum2!=0) // sum=sum+(sum2)*-1; printf("%lld\n",sum*-1); } //printf("Hello World"); return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
ae789455ac80de1acf67f6a4d0c683e6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> int main() { int t; scanf("%d", &t); while (t-- > 0) { int n; scanf("%d", &n); int a; long long result = 0; long long temp = 0; while (n-- > 0) { scanf("%d", &a); if (a < 0) { temp += a; if (temp < 0) { result -= temp; temp = 0; } } else { temp += a; } } printf("%lld\n", result); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
ba02711485db5bb290ecf4733c7ba4cb
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> int main(void) { int t; scanf("%d",&t); while(t) { int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } //long sum=0; long long cur=0; for(int i=0;i<n;i++) { cur=cur+a[i]; /* if((a[i+1]>0)&&(cur<0)) { sum=sum+cur; cur=0; }*/ if(cur<0) cur=0; } printf("%lld\n",cur); t--; } }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
223f155e629e9d344c919db1bf512103
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> #include<limits.h> typedef long long ll; void swap(ll *a, ll *b) { ll temp = *a; *a = *b; *b = temp; } /*void quicksort(ll arr[], ll l, ll r) { if (l >= r) { return; } ll pivot = arr[r]; ll cnt = l; for (ll i = l; i <= r; i++) { if (arr[i] <= pivot) { swap(&arr[cnt], &arr[i]); cnt++; } } quicksort(arr, l, cnt-2); quicksort(arr, cnt, r); }*/ int main() { int t; scanf("%d",&t); while(t--) { ll a[100000],n,cn=0,add=0; scanf("%lld",&n); // printf("n=%d\n",n); for(ll i=0;i<n;i++) scanf("%lld",&a[i]); for(ll i=0;i<n;i++) { ll no=0; if(a[i]>0) add+=a[i]; else{ no=add+a[i]; if(no>0) add=no; else { add=0; cn=cn-no; } } //printf("cn=%lld %lld\n",cn,add); } printf("%lld\n",cn); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
64c04b61b5640963493b1a565af6dbcd
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include<stdio.h> int main(){long long int t,i,n,j,a[100000],sum; scanf("%lld",&t); for(i=0;i<t;i++) { scanf("%lld",&n); for(j=0;j<n;j++) { scanf("%lld",&a[j]); } sum=0; for(j=0;j<n;j++) { sum=sum+a[j]; if(sum<0) sum=0; } printf("%lld\n",sum); } return 0; }
You're given an array $$$a$$$ of $$$n$$$ integers, such that $$$a_1 + a_2 + \cdots + a_n = 0$$$.In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), decrement $$$a_i$$$ by one and increment $$$a_j$$$ by one. If $$$i &lt; j$$$ this operation is free, otherwise it costs one coin.How many coins do you have to spend in order to make all elements equal to $$$0$$$?
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $$$0$$$.
C
bd0b14e53ade1207022464ebafdf8c9a
b40d5093d869c8766f83af95b6a4f8d1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1599402900
["7\n4\n-3 5 -3 1\n2\n1 -1\n4\n-3 2 -3 4\n4\n-1 1 1 -1\n7\n-5 7 -6 -4 17 -13 4\n6\n-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000\n1\n0"]
NotePossible strategy for the first test case: Do $$$(i=2, j=3)$$$ three times (free), $$$a = [-3, 2, 0, 1]$$$. Do $$$(i=2, j=1)$$$ two times (pay two coins), $$$a = [-1, 0, 0, 1]$$$. Do $$$(i=4, j=1)$$$ one time (pay one coin), $$$a = [0, 0, 0, 0]$$$.
PASSED
1,000
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) Β β€” the number of elements. The next line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is given that $$$\sum_{i=1}^n a_i = 0$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
["3\n0\n4\n1\n8\n3000000000\n0"]
#include <stdio.h> int main(void) { // your code goes here long long int t,n,ar[1000000],i,s,z,j,neg; scanf("%lld",&t); for(z=1;z<=t;z++) { scanf("%lld",&n); s=0;neg=0; for(j=0;j<n;j++) { scanf("%lld",&ar[j]); if(ar[j]<0) { neg-=ar[j]; if(s>(-ar[j])) { neg+=ar[j]; s+=ar[j]; } else { neg-=s; s=0; } } else s+=ar[j]; } printf("%lld\n",neg); } return 0; }