import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static int[] jobOffers(int scores[],int lowerLimit[],int
upperLimit[]){
int offers[] = new int[lowerLimit.length];
HashMap<Integer,Integer> hm = new HashMap<>();
for(int i=0;i<scores.length;i++){
Integer count = (hm.get(scores[i])==null ? 0 :
hm.get(scores[i]));
count++;
hm.put(scores[i],count);
}
for(int i=0;i<lowerLimit.length;i++){
int ll=lowerLimit[i];
int up= upperLimit[i];
int count =0;
if(ll!=up){
for(int j=ll;j<=up;j++){
int addcount = (hm.get(j)==null ? 0 : hm.get(j));
count = count + addcount;
}
}
else{
int addcount1 = (hm.get(ll)==null ? 0 : hm.get(ll));
count = addcount1;
}
offers[i]= count;
}
return offers;
}
public static void main (String[] args) throws
java.lang.Exception
{
// your code goes here
int n,q;
Scanner sc = new
Scanner(System.in);
n= sc.nextInt();
q= sc.nextInt();
int[] scores = new int[n];
int[] upperLimit = new
int[q];
int[] lowerLimit = new
int[q];
int[] offers = new int[q];
for(int i=0;i<n;i++){
scores[i]=sc.nextInt();
}
for(int i=0;i<q;i++){
lowerLimit[i]=sc.nextInt();
}
for(int i=0;i<q;i++){
upperLimit[i]=sc.nextInt();
}
offers =
jobOffers(scores,lowerLimit,upperLimit);
for(int i=0;i<q;i++){
System.out.println(offers[i]);
}
}
}
//code:
//sample execution:
Language: Java View site information Pevchometric testing is designed to find JUDICIO VAIT mormation about an...
Language: java
An investor opens a new account and wants to invest in a number of assets. Each asset begins with a balance of O, and its value is stored in an array using 1-based indexing. Periodically, a contribution is received and equal investments are made in a subset of the portfolio. Each contribution will be given by investment amount, start index, end index. Each investment in that range will receive the contribution amount. Determine the maximum amount invested in...
Java 8
9m left Jav 27 28 ALL 29 0 Given an integer array, separate the values of the array into two subsets, A and B, whose intersection is null and where the addition of the two subsets equals the entire array. The sum of values in set A must be strictly greater than the sum of values in set B, and the number of elements in set A must be minimal. Return the values in set A in increasing...
LANGUAGE: JAVA
An online coin dealer offers bags of coins that are guaranteed to contain at least one full set. Given a string comprised of lowercase letters in the range ascii[a-z), where each letter represents a coin type, determine the length of the shortest substring that contains at least one of each type of coin. Example: coins = dabbcabcd The list of all characters in the string is (a, b, c, d]. Two of the substrings that contain all letters...
Please use Java for this question.
Input Format Format for Custom Testing Input from stdin will be processed as follows and passed to the function In the first line, there is a single integer n. In the second line, there is a single integer m. In the ph of the next n lines there are m space-separated integers denoting the throw of the initial grid. In the next line, there is a single integer k. In the next line,...
What an Executive Summary Is
An executive summary is a specific type of document that does
two things: it summarizes a research article, and it offers
recommendations as to how information from the article can be
used.
Some long reports can contain an executive summary section, as
indicated in the Pearson handbook.
Write a 2 pahe Executive Summary
In business contexts, an executive summary is always written
for a specific purpose: to explain the information in the article
to a...