#include <iostream> using namespace std; int main() { int leavingCars, minutes; int carPerMinute[100]; int totalCars = 0;
cin >> leavingCars >> minutes; int carsLeavingPerMinute = leavingCars * minutes;
for(int index = 1; index <= minutes; ++index) { cin >> carPerMinute[index]; totalCars += carPerMinute[index]; }
cout << totalCars - carsLeavingPerMinute;
return 0; } k, n = [int(x) for x in input().split()] a = list(map(int, input().split())) m = 0 for i in a: m += i if (m - k >= 0): m -= k else: m = 0 print(m) explain please. for whar we need n then? try this example: 4 3 1 5 6 You cannot pass the sixth test. In the first minute there are 0 cars left. In the second minute there was 1 car left. At the third minute there were 2+1 cars left. Read the conditions of the task more carefully. )))) Test in you code example like this 4 3 1 5 6 Wrong Answer is 0. Thrue Answer is 3. Be confident!!! Why this piece of code showing wrong answer. I have tested your input it has given correct output. #include<iostream> using namespace std; int main(){ int k, n, arr[101],x=0; cin>>k>>n;
for(int i=0; i<n; i++){ cin>> arr[i];
} for(int i=0;i<n;i++){ if(k>=arr[i]){ if(i != n-1){ x = x + arr[i+1]; arr[i+1] = x;
x = 0;
} else{ x = 0; }
} else{ if(i != n-1){ x = (arr[i]-k) + arr[i+1]; arr[i+1] = x;
} else{ x = arr[i] - k; } } // printf("X : %d\n",x); } if(x<=0) cout<<0; else cout<<x;
} #include<iostream> using namespace std; int main(){ int k, n, arr[101],x=0; cin>>k>>n;
for(int i=0; i<n; i++){ cin>> arr[i];
} for(int i=0;i<n;i++){ if(k>=arr[i]){ if(i != n-1){ x = x + arr[i+1]; arr[i+1] = x;
x = 0;
} else{ x = 0; }
} else{ if(i != n-1){ x = (arr[i]-k) + arr[i+1]; arr[i+1] = x;
} else{ x = arr[i] - k; } } // printf("X : %d\n",x); } if(x<=0) cout<<0; else cout<<x;
} k, n = [int(i) for i in input().split()] a = [int(i) for i in input().split()] if sum(a) - n * k <= 0: print(0) else: print(sum(a) - n * k) If you have problems with test case 6, then please check the following: If you have wrong anwer at test 6, try this test: 4 3 3 4 5 Correct answer: 1 Because at ith minute, there is only a[i] cars come to the traffic jam. Good luck to you! Thanks to sign_in158. oh... i understand,thank you! I am very happy . Thank you . I am understand this Problem Thanks Edited by author 07.01.2015 01:03 Edited by author 21.02.2015 01:13 Edited by author 21.02.2015 01:14 Thank you. I understand now. #include <iostream> using namespace std; int main() {
int n, k; cin >> n >> k; int c = n * k; int *arr = new int[k];
for (int i = 0; i < k; i++) { cin >> arr[i]; c = c - arr[i]; }
cout << abs(c);
} Edited by author 11.02.2019 20:58 помогите найти ошибку. вроде ответы правильные выдаёт using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(); int b = Convert.ToInt32(a[0]); int c = Convert.ToInt32(a[1]); int d = 0; string[] e = Console.ReadLine().Split(); for (int f = 0; f < c; f++ ) { d = d + Convert.ToInt32(e[f]); } int g = d - b * c; if (g < 0) { g = 0; } Console.WriteLine(g); Console.ReadLine(); } } } wtf? what`s wrong? program asd; var n,k,i:byte; r:word; a:array[1..100] of byte; BEGIN r:=0; ReadLn(k,n); for i:=1 to n do begin Read(a[i]); if (r+a[i]-k)>=0 then r:=r+a[i]-k else r:=0; end; WriteLn(r); END. Hi array must be [1..101] because you need to put the latest integer into this cell #include <iostream> using namespace std; int main() { int k,n,l=1; int r=0; int* a = new int[1]; cin >> k >> n; cin >> a[0]; for(int i=1;cin >> a[i];i++) l+=1; for(int i=0;i<n;i++){ if(i<l) r+=a[i]; r-=k; if(r<0) r=0; } cout << r << endl; system("pause"); return 0; } Что не так? Edited by author 06.11.2013 23:12 int* a = new int[1]; LOLWUT? This is a dynamic array. The number in [] has no importance. An array is okay Edited by author 06.11.2013 23:14 All right. Thanks for the information. But I find it hard to understand how I should use it in the program. Please correct my code .. In this case, just don't use pointers. You can declare an array using following syntax: Typename variableName[ arraySize ]; Exapmle: int array[ 100 ]; In this example, an array of 100 int elements will be created. I suppose, that most of problems from archive can be solved without using dynamic memory allocation. Edited by author 07.11.2013 12:30 #include <iostream> using namespace std; int main() { int k,n,s,i,g,r; cin>>k; s=0; cin>>n; int *a=new int[n]; for (i=0;i<n;i++){ cin>>a[i]; s=a[i]+s; }; g=s-(n*k); cout<<g; return 0; } consider this situation: when the number of the remaining cars until the current moment is less than k. for example 5 3 3 6 5 the result is 1 not 0 #include<iostream> using namespace std; int main() { int k, n, a[1010], A, sklad; cin >> k >> n; if ((1 <= k && k <= 100) && (1 <= n && n <= 100)) { for (int b = 0; b < n; b++) { cin >> a[b]; } sklad = 0; for (int c = 0; c < n; c++) { A = k - (a[c] + sklad); if (A < 0) { sklad = -A; } else sklad = 0; } if (A < 0) { cout << -A; } else cout << A; } return 0; } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Task1787 { class Program { static void Main(string[] args) { string[] kMinute = Console.ReadLine().Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); int k = int.Parse(kMinute[0]); int n = int.Parse(kMinute[1]); string[] nCam = Console.ReadLine().Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); int sum = 0; foreach (var item in nCam) { sum += int.Parse(item); } Console.WriteLine(sum - (k * n)); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace РџРѕРІРѕСЂРѕС‚ { class Program { static void Main(string[] args) { string[] mas = Console.ReadLine().Split(' '); int k = int.Parse(mas[0]); int n = int.Parse(mas[1]); int[] A = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(i => int.Parse(i)).ToArray(); int M = 0; for (int i = 0; i < n; i++) { M += A[i]; if (M - k >= 0) {M -= k;} else {M = 0;} } Console.WriteLine(M); } } } Надеюсь понятно всё. #include <iostream> using namespace std;
int main() { int k, n, res=0; cin >> k >> n; int *mas = new int[n];
for (int i=0; i!=n; i++) { cin >> mas[i];
if (mas[i] > k) { res = res + (mas[i] - k); } else { if (res!=0 ) { if ((k - mas[i]) > res) { res = 0; } else { res = res - (k - mas[i]); } } }
} cout << res; return 0; } This is the mean. Edited by author 17.01.2018 14:44 var k,n,i,q,w:integer; begin read(k,n); for i:=1 to n do begin read(q); w:=w+q; end; if k*n>=w then writeln(0) else writeln(w-k*n); end. import java.util.*; import java.io.*; public class MEGA { public static void main(String arg[]) { int k,n,i,sum=0; Scanner scan=new Scanner(System.in); k=scan.nextInt(); n=scan.nextInt(); int[] a=new int[n]; for(i=0;i<n;) { if(scan.hasNextInt()) { a[i]=scan.nextInt(); i++; } } for(i=0;i<n;i++) { sum+=a[i]-k; } if(sum<0) { System.out.println("1"); } else { System.out.println(""+sum); } } } This very simple program is turning out to be a headache. What is Test #3? inside cycle you need to check that (sum + a[i] - k) >=0 Edited by author 04.12.2016 16:18 Edited by author 04.12.2016 16:18 #include <iostream> using namespace std; int main() { int k; cin >> k; int n; cin >> n; int change; int result = 0; for (int i = 0; i < n; i++) { cin >> change; result += change; } if (result - k*n >= 0) cout << result - k*n; else cout << 0; return 0; } Author's behavior. 1) You should explain what problem is - WA/TLE/runtime error. 2) You should better remove/clear/add explanation to post after you solved task yourself. Edited by author 16.08.2016 21:18 Whats wrong with my code. I get correct answer for Test 6 on my compiler, but when I submit the solution, I get wrong answer. Please help!! I tried with below values and got correct answer 4 3 3 4 5 Correct answer: 1 #include <iostream> using namespace std; int main() { int a,k,n,d; int b=0; cin>>k>>n>>d; for (int i=0;i<n-1;i++) { cin>>a; a=a-k; b=b+a; } if (d-k>=0) { if (b+d-k>=0) cout<<b+d-k; else cout<<0; }
else if (b>0) cout<<b; else cout<<0; char f; cin>>f; } I have some problem, try 5 4 3 , you must have 0. |
|