Computer Science, asked by chandravamshi54, 16 hours ago

The cloud computing company Cloud0 can accommodate various requirements for resources. The company system runs two servers. For load balancing purposes, the load of the resources gets transferred to the serves one by one. Initially, the first request goes to server 1. the next request goes to server 2. and so an. The requests served by the servers are two types i.e. one for memory deallocation (denoted by a negative number).

Write an algorithm to find the total number dounits of memory allocated/deallocated by the server 1 after processing all the requests.

Input:
The first line of the input consists of an integer numOfReq, representing the
number of requests(N).
The second line consists of N space-separated integers-req.req req representing the requests for the allocation/deallocation of the respective memory units.

Output:
Return an integer representing the total number of units of memory
allocation/deallocated by the server 1 after processing all the requests.

Constraints:
0<_numOfReq<10^{5}
- 10^{6}<_req<10^{6}
0
Example
Input
7
2-3-8-6-7181
Output
4

Explanation
The requests served by server 1 are [2,8,-7,1] So, the total processing time of server 2 is 4.

TEST CASES:
TestCase1:
Input
5
14 53 2 23 1
Expected Return Value
17

TestCase2:
Input:
6
542 32 56 88 12
Expected Return Value: 174

Answers

Answered by GanpatiKumarRoy
42

Answer:

Python3 Solution:-

print("Ganpati Kumar Roy")

Explanation:

def memServer1(req):

   sum = 0

   n = len(req)

   for i in range (0, n):

       if(i%2 == 0):

           sum += req[i]

   return sum

req = []

req_size = int(input("Enter the size:-\t"))

req = list(map(int, input().split()))

result = memServer1(req)

print(result)

Answered by Anonymous
10

Answer:

C Program:

#include<stdio.h>

int main()

{

int n,i,sum=0;

scanf("%d",&n);

int arr[n];

for(i=0;i<n;i++)

{

scanf("%d",&arr[i]);

}

for(i=0;i<n;i++)

{

if(i%2==0)

{

sum=sum-arr[i];

}

}

printf("%d",sum);

return 0;

}

Explanation:

Similar questions