Questions
Stacks & Queues C++ You are given a stack of N integers such that the first...

Stacks & Queues
C++

You are given a stack of N integers such that the first element represents the top of the stack and the last element represents the bottom of the stack. You need to pop at least one element from the stack. At any one moment, you can convert stack into a queue. The bottom of the stack represents the front of the queue. You cannot convert the queue back into a stack. Your task is to remove exactly K elements such that the sum of the K removed elements is maximized.

Input format :
The first line consists of two space-separated integers N and K. The second line consists of N space-separated integers denoting the elements of the stack.

Output format : Print the maximum possible sum of the K removed elements

Sample Input:

10 5
10 9 1 2 3 4 5 6 7 8

Sample Output:

40

Explanation Pop two elements from the stack. i.e {10,9} Then convert the stack into queue and remove first three elements from the queue. i.e {8,7,6}. The maximum possible sum is 10+9+8+7+6 = 40

This is my code so far

#include <iostream>
#include <deque>
std::deque<int> stacque;
using namespace std;
void printDeque(deque<int> vector) {
for(int i=0;(unsigned)i<vector.size();i++) {
cout<<vector.at(i)<<" ";
}
cout<<endl;
}


int main() {
int n,q;
cin>>n;
cin>>q;
for(int i=0;i<n;i++){
int x;
cin>>x;
stacque.push_back(x);
}
/*cout<<n<<" "<<q<<endl;
printDeque(stacque);*/

int sum=0;
for(int i=0;i<q;i++){
  
if(stacque.front()>stacque.back()){
int a;
a=stacque.front();
sum+=a;
stacque.pop_front();
  
}
else {
int b;
b=stacque.back();
sum+=b;
stacque.pop_back();
  
}
}
cout<<sum<<endl;

return 0;
}


my output for the test is nearly correct but its only slightly off

input test 1

420 135
46 1 19 60 86 64 5 98 4 85 93 25 82 56 83 31 92 23 77 36 17 63 31 61 92 31 86 82 91 84 26 54 27 61 95 87 53 50 72 30 73 49 35 4 21 36 73 50 97 70 95 7 81 92 76 33 77 48 50 100 80 22 35 67 40 56 28 31 31 60 8 10 31 76 99 69 56 65 2 79 15 5 68 82 55 60 16 95 44 34 2 54 71 88 100 100 76 16 49 46 69 90 41 11 33 45 8 58 37 40 9 65 50 79 15 54 6 98 11 56 77 20 89 22 18 24 33 12 52 33 31 31 71 1 26 68 62 53 14 5 70 79 18 12 71 93 60 37 23 86 8 31 73 71 76 70 51 88 55 68 59 100 45 49 16 35 61 78 29 80 74 19 56 72 92 49 17 86 17 48 58 68 57 100 31 87 38 11 63 7 48 59 73 69 84 58 77 74 1 4 55 53 52 96 99 74 77 8 44 40 55 50 99 28 13 40 83 43 68 97 53 81 53 49 86 68 87 92 22 65 26 2 14 62 51 76 67 1 20 99 60 13 72 69 17 55 92 94 1 28 69 72 71 42 31 79 83 100 71 56 91 40 20 33 1 12 96 27 95 29 57 40 70 57 8 80 93 4 30 31 82 53 98 67 75 6 60 49 23 54 52 67 84 71 67 85 92 58 42 80 40 87 60 55 17 73 90 3 55 2 63 86 53 60 71 16 34 46 1 49 10 82 4 67 64 3 91 20 56 98 22 45 14 85 93 3 54 77 31 49 67 15 32 31 18 7 95 34 12 96 99 30 88 91 42 85 72 74 12 4 40 97 79 65 29 29 48 76 35 73 66 39 9 86 7 99 22 46 66 48 21 30 52 69 22 26 16 52 48 62 55 97 60 86 86 59 68 94 21 51 90 32 32 94 12 96 29 73 4 98 13 80 72 67 18 68 15 26 79 38
Your output
7033
Your output does not contain
7510

input test 2

Input
490 231
68 51 46 65 74 64 38 94 96 65 39 9 26 86 99 93 37 65 11 86 53 45 40 56 43 32 98 70 57 89 36 38 51 62 23 86 18 55 30 37 52 21 59 60 15 78 84 23 98 44 78 68 94 49 59 43 63 91 71 9 75 89 76 23 100 59 18 97 89 2 25 33 59 48 84 50 78 71 84 3 96 60 7 38 11 16 99 41 11 91 65 8 10 29 14 88 7 70 80 56 38 54 16 42 1 70 1 96 97 62 82 42 17 84 96 73 77 78 85 82 27 72 33 57 38 57 95 76 59 32 26 76 9 22 19 88 14 43 46 13 20 7 7 62 58 76 54 92 35 78 17 86 5 86 27 44 75 76 15 21 34 15 14 83 62 95 40 42 45 16 10 38 77 1 90 72 27 72 22 75 93 49 82 52 95 6 76 55 66 66 53 85 70 61 38 64 22 33 58 50 63 39 35 90 54 53 45 71 95 93 78 51 47 94 81 6 26 22 18 1 82 77 86 49 100 5 88 40 4 60 79 26 88 38 12 81 70 95 80 37 28 57 80 68 1 43 9 10 42 16 18 67 99 3 41 50 35 48 42 42 16 47 11 75 52 76 33 60 10 47 96 5 12 10 86 61 80 86 58 45 63 95 33 51 38 45 95 2 49 76 10 50 3 62 39 94 47 33 54 99 76 60 57 2 8 47 18 90 28 99 66 47 8 95 85 25 42 90 27 66 100 22 18 93 95 83 27 89 4 21 39 80 46 14 46 58 55 12 83 95 99 3 86 8 43 92 24 72 7 47 34 78 77 87 100 3 11 72 86 37 48 68 28 9 92 59 95 39 59 97 64 21 95 94 25 48 42 91 76 16 97 72 71 49 24 30 18 90 64 10 44 6 87 95 37 90 52 37 53 86 54 95 11 28 83 12 65 87 73 58 83 9 85 20 15 73 21 39 87 73 75 44 50 99 37 92 82 66 68 60 72 60 25 72 35 11 67 4 86 1 10 3 79 28 2 44 29 33 71 22 99 13 77 3 36 54 17 61 79 77 83 34 39 31 100 46 23 54 83 3 13 62 31 81 58 17 16 92 54 92 39 51 37 68 94 63 73 26 45 1
Your output
12257
Your output does not contain
12595

i passed one of the tests but these 2 are only slightly off and i dont know why.
please provide a solution in C++

In: Computer Science

A fund manager has a well-diversified portfolio that mirrors the performance of the S&P 500 and...

A fund manager has a well-diversified portfolio that mirrors the performance of the S&P 500 and is worth $360 million. The value of the S&P 500 is 1,200, and the portfolio manager would like to buy insurance against a reduction of more than 5% in the value of the portfolio over the next six months. The risk-free interest rate is 6% per annum. The dividend yield on both the portfolio and the S&P 500 is 3%, and the volatility of the index is 30% per annum.

a. If the fund manager buys traded European put options, how much would the insurance cost?

b. Explain carefully alternative strategies open to the fund manager involving traded European call options, and show that they lead to the same result.

c. If the fund manager decides to provide insurance by keeping part of the portfolio in risk-free securities, what should the initial position be?

d. If the fund manager decides to provide insurance by using nine-month index futures, what should the initial position be?

In: Finance

QUESTION 1 Even though an investee may be an associate of an investor, if the shares...

QUESTION 1

  1. Even though an investee may be an associate of an investor, if the shares of that associate are traded in an active market, AASB128 Investment in Associates and Joint Ventures requires the application of the:

    market valuation.

    consolidation method.

    equity method.

    valuation made by an independent evaluator.

QUESTION 2

  1. Indicia of an investor’s incapacity to exert significant influence over the policy-making decisions of an investee include:

    the existence of a small group of ‘non-investor’ shareholders representing the majority of voting power in the investee.

    the investor attempting to gain, but not gaining, board representation.

    the investor attempting to gain, but not gaining, the financial information necessary to calculate its equity in the fair value of the investee’s net assets at the date of acquisition, or its equity in the post-acquisition earnings of the investee.

    all of the above.

QUESTION 3

  1. The accounting method applied to investments in associates, known as the equity method, is also known as the:

    significant influence method.

    multi-line consolidation method.

    entity method of consolidation.

    one-line consolidation method.

QUESTION 4

  1. Goodwill acquired in an associate is:

    amortised across its useful life.

    carried as a separate asset in the accounting records of the investor.

    written off immediately against the carrying amount of the investment.

    not subject to amortisation.

QUESTION 5

  1. Red Limited acquired a 30% investment in Blue Limited for $1,000,000. Blue declared and paid a dividend of $20,000 during the current year. Red Limited prepares consolidated financial statements. Which of the following is the appropriate entry for Red Limited to record this dividend?

    DR    Dividends payable                   $6,000

                   CR                  Cash                                 $6,000

    DR    Dividend revenue         $6,000

                   CR                  Investment in associate      $6,000

    DR    Cash                                        $6,000

                   CR                  Dividend revenue         $6,000

    DR    Cash                                           $6,000

                   CR                  Investment in associate      $6,000

  

In: Accounting

Making Business Decisions: Analyzing Apple’s Inventory Turnover Ratio You are considering an investment in the common...

Making Business Decisions: Analyzing Apple’s Inventory Turnover Ratio

You are considering an investment in the common stock of Apple Inc. The following information is from the financial statements included in Form 10-K for fiscal years 2015 and 2014 (in millions of dollars):

Cost of sales for the year ended:
September 26, 2015 $140,089
September 27, 2014 112,258
Inventories:
September 26, 2015 2,349
September 27, 2014 2,111
September 29, 2013 1,764

The following information is from the financial statements included in Form 10-K for fiscal years 2015 and 2014 for Hewlett-Packard Company (in millions of dollars):

Cost of sales for the year ended:
October 31, 2015 $53,081
October 31, 2014 56,469
Inventory:
October 31, 2015 6,485
October 31, 2014 6,415
October 31, 2013 6,046

Use 360 days a year.

Required:

1. Calculate the inventory turnover ratios for Apple Inc. and Hewlett-Packard Company for the years ending September 26, 2015 and October 31, 2015, respectively. If required, round your answers to one decimal place.

Apple Inc.: ____times
Hewlett-Packard: _____times

2. Which company appears to be performing better?
A. Helett-Packard

B. Apple Inc.

3. Assume Company A has an inventory turnover ratio of 52.8 times and Company B has inventory turnover ratio of 12.6. Based on this information, which of the following statement is correct?

A. Company A is performing better, when it comes to inventory management.

B. Company B is performing better, when it comes to inventory management.

C. Company A sells its product every 6.2 days.

D. Company B sells its products every 4.9 days.

In: Finance

Casino Ltd is a company that owns a large holiday resort on Queensland’s Gold Coast. Casino...

Casino Ltd is a company that owns a large holiday resort on Queensland’s Gold Coast. Casino Ltd employs 100 people who work in the catering, cleaning and the hospitality outlets of the resort. The company and its employees have had a history of industrial disputes involving wages and conditions. After the most recent dispute, Casino Ltd and its employees came to an agreement on 1 July 2005, under which it was agreed that all of its employees were to be paid wages and salaries that are in excess of other employees working in similar resorts in Australia. One month after the agreement was made, a new company was incorporated which is a wholly owned subsidiary of Casino Ltd. The new company is called Caterers Ltd. It has three directors, all of whom are appointed from the board of five directors of Casino Ltd. Caterers Ltd.’s constitution had a clause which stated that all of the profits of Caterers Ltd will be distributed as dividend to Casino Ltd. The incorporation of Caterers Ltd was preceded by a meeting between the board of directors and the senior managers of Casino Ltd where the reason for the creation of the new entity was discussed. The senior managers of Casino Ltd devised a strategic plan which called for a new corporate structure which will take into account that the catering and entertainment services of Casino Ltd has the potential to become a significant operation in its own right both within and outside the resort. The directors of Casino Ltd were genuinely impressed with the plan and believed it was in the long term interests of the company. They passed a resolution that the management of Casino Ltd put into place matters that will allow Caterers Ltd to pursue this new strategic objective. The redevelopment of the current resort was central to the management plan approved by the board of Casino Ltd in relation to the creation of Caterers. This meant closure of many of the restaurants in the resort and the redundancy of 60 employees. These redundant employees were offered new, but identical, positions working in Caterers Ltd. Faced with the choice of an uncertain future, all 60 employees accepted the job offer with Caterers Ltd. As a result, the redundant employees no longer work under the previous 1 July 2005 contract of employment they had while working for Casino Ltd. Instead, they work under wages and conditions that are not as favourable as they had while working for Casino Ltd. However, these wages and conditions are comparable to people who work in similar industries. Caterers Ltd, through its employees, started running the catering and entertainment services in the resort and due to the huge success of the business, Caterers expanded beyond the resort and started leasing outside premises to run a bigger catering and entertainment business. The Trade Union, on behalf of the 60 employees working for Caterers Ltd is concerned about the practical effect of this corporate reorganization on employment conditions. Assuming that the 1 July 2005 agreement between Casino Ltd and its employees is valid and that Caterers Ltd has been validly incorporated, advice the trade union as to its chances of success in enforcing that agreement. Refer to relevant statutes and case law based on Company Law.  

In: Operations Management

Please Answer Required # 1,2 and 3 as Soon as Possible. Thank you Required: #1. Prepare...

Please Answer Required # 1,2 and 3 as Soon as Possible. Thank you

Required: #1. Prepare journal entries to record the December transactions in the General Journal Tab in the excel template file "Accounting Cycle Excel Template.xlsx". Use the following accounts as appropriate: Cash, Accounts Receivable, Supplies, Prepaid Insurance, Equipment, Accumulated Depreciation, Accounts Payable, Wages Payable, Common Stock, Retained Earnings, Dividends, Service Revenue, Depreciation Expense, Wages Expense, Supplies Expense, Rent Expense, and Insurance Expense.
1-Dec Began business by depositing $9000 in a bank account in the name of the company in exchange for
900 shares of $10 per share common stock.
1-Dec Paid the rent for the current month, $800 .
1-Dec Paid the premium on a one-year insurance policy, $1200 .
1-Dec Purchased Equipment for $3600 cash.
5-Dec Purchased office supplies from XYZ Company on account, $300 .
15-Dec Provided services to customers for $6600 cash.
16-Dec Provided service to customers ABC Inc. on account, $4300 .
21-Dec Received $2100 cash from ABC Inc., customer on account.
23-Dec Paid $170 to XYZ company for supplies purchased on account on December 5 .
28-Dec Paid wages for the period December 1 through December 28, $4760 .
30-Dec Declared and paid dividend to stockholders $200 .
#2. Post all of the December transactions from the “General Journal” tab to the T-accounts under the “T-Accounts” tab in the excel template file "Accounting Cycle Excel Template.xlsx". Assume there are no beginning balances in any of the accounts.  
#3. Compute the balance for each T-account after all of the entries have been posted. These are the unadjusted balance as of December 31.
#4. Prepare the unadjusted trial balance under the “Unadjusted Trial Balance” tab in the excel template file "Accounting Cycle Excel Template.xlsx" .
Provide the total of the credit column from the Unadjusted Trial Balance
#5. Record the following four transactions as adjusting entries under the “General Journal” tab.
31-Dec One month’s insurance has been used by the company $100.
31-Dec The remaining inventory of unused office supplies is $90.
31-Dec The estimated depreciation on equipment is $60.
31-Dec Wages incurred from December 29 to December 31 but not yet paid or recorded total $510.

In: Accounting

Fast Pizza hires college students who drive their own cars to deliver pizzas to customers. Fast...

Fast Pizza hires college students who drive their own cars to deliver pizzas to customers. Fast Pizza is concerned that the company may be liable for damages caused by company employees while they are driving their cars on company business.

Part 1: Discuss the loss exposures to both Fast Pizza’s business operation and to the students who are driving their own cars to deliver pizzas.

Part 2: Identify a commercial auto liability coverage that Fast Pizza could purchase to address their exposures.

Part 3: Discuss how the coverage purchased in Part 2 could impact the student drivers.  Use a loss scenario to illustrate.

In: Operations Management

Greg’s Bicycle Shop has the following transactions related to its top-selling Mongoose mountain bike for the...

Greg’s Bicycle Shop has the following transactions related to its top-selling Mongoose mountain bike for the month of March. Greg's Bicycle Shop uses a periodic inventory system.

Date Transactions Units Unit Cost Total Cost
March 1 Beginning inventory 20 $ 225 $ 4,500
March 5 Sale ($350 each) 15
March 9 Purchase 10 245 2,450
March 17 Sale ($400 each) 8
March 22 Purchase 10 255 2,550
March 27 Sale ($425 each) 12
March 30 Purchase 7 275 1,925
$ 11,425

  5. Calculate sales revenue and gross profit under each of the four methods. (Round weighted-average cost amounts to 2 decimal places.)
  

specific identification FIFO LIFO Weighted Average Cost
Sales Revenue
Gross Profit

In: Accounting

Pricing Strategy, Sales Variances Eastman, Inc., manufactures and sells three products: R, S, and T. In...

Pricing Strategy, Sales Variances

Eastman, Inc., manufactures and sells three products: R, S, and T. In January, Eastman, Inc., budgeted sales of the following.

Budgeted
Volume
Budgeted
Price
Product R 111,300        $29       
Product S 145,100        23       
Product T 16,200        19       

At the end of the year, actual sales revenue for Product R and Product S was $3,069,900 and $3,480,400, respectively. The actual price charged for Product R was $27 and for Product S was $22. Only $8 was charged for Product T to encourage more consumers to buy it, and actual sales revenue equaled $343,200 for this product.

Required:

1. Calculate the sales price and sales volume variances for each of the three products based on the original budget.

Sales price variance Sales volume variance
Product R $ Unfavorable $ Favorable
Product S $ Unfavorable $ Favorable
Product T $ Unfavorable $ Favorable

In: Accounting

The unadjusted trial balance as of December 31, 2021, for the Bagley Consulting Company appears below....

The unadjusted trial balance as of December 31, 2021, for the Bagley Consulting Company appears below. December 31 is the company’s reporting year-end.

Account Title Debits Credits
Cash 9,950
Accounts receivable 8,000
Prepaid insurance 3,300
Land 220,000
Buildings 62,500
Accumulated depreciation—buildings 25,000
Office equipment 96,000
Accumulated depreciation—office equipment 38,400
Accounts payable 29,200
Salaries payable 0
Deferred rent revenue 0
Common stock 240,000
Retained earnings 47,400
Service revenue 83,500
Interest revenue 4,400
Rent revenue 5,400
Salaries expense 33,000
Depreciation expense 0
Insurance expense 0
Utilities expense 21,700
Maintenance expense 18,850
Totals 473,300 473,300


Information necessary to prepare the year-end adjusting entries appears below.

  1. The buildings have an estimated useful life of 50 years with no salvage value. The company uses the straight-line depreciation method.
  2. The office equipment is depreciated at 10 percent of original cost per year.
  3. Prepaid insurance expired during the year, $1,650.
  4. Accrued salaries at year-end, $1,300.
  5. Deferred rent revenue at year-end should be $850.


Required:
1.
From the trial balance and information given, prepare adjusting entries.
2. Post the beginning balances and adjusting entries into the appropriate T-accounts.
3. Prepare an adjusted trial balance.
4. Prepare closing entries.
5. Prepare a post-closing trial balance.

From the trial balance and information given, prepare adjusting entries. (If no entry is required for a transaction/event, select "No journal entry required" in the first account field.)

  • The buildings have an estimated useful life of 50 years with no salvage value. The company uses the straight-line depreciation method.
  • The office equipment is depreciated at 10 percent of original cost per year.
  • Prepaid insurance expired during the year, $1,650.
  • Accrued salaries at year-end, $1,300.
  • Deferred rent revenue at year-end should be $850.
Transaction General Journal Debit Credit
a


BAGLEY CONSULTING COMPANY
Adjusted Trial Balance
Account Title Debits Credits
Cash
Accounts receivable
Prepaid insurance
Land
Buildings
Accumulated depreciation—buildings
Office equipment
Accumulated depreciation—office equipment
Accounts payable
Salaries payable
Deferred rent revenue
Common stock
Retained earnings
Service revenue
Interest revenue
Rent revenue
Salaries expense
Depreciation expense
Insurance expense
Utilities expense
Maintenance expense
Totals $0 $0

Prepare closing entries. (If no entry is required for a transaction/event, select "No journal entry required" in the first account field.)

  • Close the revenue accounts using Retained Earnings.
  • Close the expense accounts using Retained Earnings.
Date General Journal Debit Credit
December 31, 2021

Prepare a post-closing trial balance.

BAGLEY CONSULTING COMPANY
Post-Closing Trial Balance
Account Title Debits Credits
Cash
Accounts receivable
Prepaid insurance
Land
Buildings
Accumulated depreciation—buildings
Office equipment
Accumulated depreciation—office equipment
Accounts payable
Salaries payable
Deferred rent revenue
Common stock
Retained earnings
Totals $0 $0

In: Accounting