369A - Valera and Plates - CodeForces Solution


greedy implementation *900

Please click on ads to support us..

Python Code:

inp = list(map(int, input().split()))
numofdays = inp[0]
numofdeeplates = inp[1]
numofplates = inp[2]

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

numofcleans = 0

for i in range(0, numofdays):
	if inp2[i] == 1:
		if numofdeeplates > 0:
			numofdeeplates -= 1
		else:
			numofcleans += 1
	else: 
		if numofplates > 0:
			numofplates -= 1
		else: 
			if numofdeeplates > 0:
				numofdeeplates -= 1
			else:
				numofcleans += 1
				
print(numofcleans)
	

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   
    int n,bowl,plate;
    cin>>n>>bowl>>plate;

    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];

    int cnt_1=0,cnt_2=0,remain_1st_dish=0,remain_2nd_dish=0;
    for(int i=0; i<n; i++)
    {
        if(a[i]==1)
            cnt_1++;
        else cnt_2++;
    }

    //cout<<"cnt_1 = "<<cnt_1<<"\ncnt_2 = "<<cnt_2<<"\n";
    if(bowl<=cnt_1)
    {
        remain_1st_dish=cnt_1-bowl;
        //cnt_1=remain_1st_dish;
        cnt_1-=bowl;
        bowl=0;
    }
    else
    {
        remain_1st_dish=0;
        bowl-=cnt_1;
        cnt_1=0;
    }

    // cout<<"\n\nremain_1st_dish = "<<remain_1st_dish<<"\n";
    // cout<<"plate = "<<plate<<"\n";
    // cout<<"cnt_1 = "<<cnt_1<<"\n";
    // cout<<"cnt2 = "<<cnt_2<<"\n";
    // cout<<"bowl = "<<bowl<<"\n\n\n";


    if(plate<=cnt_2)
    {
        remain_2nd_dish=cnt_2-plate;
        cnt_2-=plate;
        plate=0;
    }
    else
    {
        remain_2nd_dish=0;

        plate=plate-cnt_2;
        cnt_2=0;
    }
    //cout<<"\n\nremain_2nd_dish = "<<remain_2nd_dish<<"\n";
    //cout<<"plate = "<<plate<<"\n";
    //cout<<"cnt2 = "<<cnt_2<<"\n";
    // cout<<"bowl = "<<bowl<<"\n\n\n";


    if(cnt_2>0 && bowl>0)
    {
        if(cnt_2>=bowl)
        {
            remain_2nd_dish=cnt_2-bowl;

            cnt_2-=bowl;
            bowl=0;
        }
        else
        {
            remain_2nd_dish=0;

            bowl=bowl-cnt_2;
            cnt_2=0;

        }
    }
    //cout<<".remain_1st_dish = "<<remain_1st_dish<<"\n";
    //cout<<".remain_2nd_dish = "<<remain_2nd_dish<<"\n";
    //cout<<"plate = "<<plate<<"\n";


    // int ans=0;
    //int x=remain_1st_dish+remain_1st_dish;
    //if(x==0)
    //    ans=0;
    //else ans=n-x;

    //if(ans<=0)
    //  cout<<0;
    //  else cout<<ans;
    cout<<remain_1st_dish+remain_2nd_dish;

}


Comments

Submit
0 Comments
More Questions

977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR