StatementYou are observing the traffic in front of your house for $N$ seconds now. You have noted down your observations. Each car starts with some initial speed $U_i$ with some constant acceleration $A_i$ at the $L_i$th second and stops in the $R_i$th second. The $\text{total speed}$ at some particular second is the sum of all the speeds of cars at that particular second. Note that cars may start with any $U$ and stop in any $V$ abruptly. For each second from $1$ to $N$, calculate the total speed for each second. Acceleration is constant but the curve isn't smooth, i.e, the speed increases abruptly at the start of a second and remains the same throughout the second. Input FormatThe first line of input will contain and integer $N$ and $M$, denoting the number of seconds and number of cars respectively. Likes $2$ to $N+1$ each contain $U_i$ $A_i$ $L_i$ $R_i$ in the same order given denoting the initial speed, accelration per second(Increase in speed per second), start time and stop time for the $i$th. Output FormatPrint $N$ integers where the $i$th integer contains the $\text{total speed}$ in the $i$th second. Constraints$1 \leq N \leq 10^6 $ ExampleInput: 10 3 1 1 1 10 2 2 1 3 1 3 5 7 Solution ExplanationWe can use the idea of "Prefix Sums" here. What we did in prefix sums is store the sum till i in an array and find the sum of a subsegment. Here, we can do something uncannily similar: In another array, we store the change in the variable we need. asked 18 Oct '17, 00:37

include <iostream>using namespace std; int main()
{
double Total_Speed,Total_Acceleration;
int U[10],A[10],L[10],R[10];
int i=0;
double N;
int V[10];
double M;
int C[10];
double Val;
cin>>N>>M;
while(i<m) {="" cin="">>U[i]>>A[i]>>R[i]>>L[i];
i++;
}
while(i<N)
{
V[i]=U[i]+A[i]*(L[i]R[i]);
Total_Speed+=V[i]+Total_Acceleration;
Total_Acceleration+=A[i]; answered 01 Nov '17, 20:52

this is my code guys can you please help me ... its exceeding the time limit answered 01 Nov '17, 20:53

So...in your code I see you took the array limits to be 10, what if m=450, Then the code does not run properly. Please take the array length as x[m]. after you input n and m. Also, using cin and cout is relatively slower than using printf and scanf. You can check how to use them online. answered 01 Nov '17, 21:46
