182B - Vasya's Calendar - CodeForces Solution


implementation *1000

Please click on ads to support us..

Python Code:

d = int(input())
n = int(input())
przhm = list(map(int, input().split()))
slv = dict()
amn = 0

for i in range (len(przhm) - 1):
    if przhm[i] == d:
        continue
    if przhm[i] not in slv:
        slv[przhm[i]] = 1
    else:
        slv[przhm[i]] += 1
        
sps = slv.items()

for j in sps:
    n_d = j[0] * j[1]
    d_d = d * j[1]
    amn = amn + (d_d - n_d)
    
print (amn)

C++ Code:

#include <bits/stdc++.h>

#define _freopen_in freopen("input.txt", "r", stdin)
#define _freopen_out freopen("output.txt", "w", stdout)
#define _fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define _cin_ignore cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define _iterator(container) container.begin(), container.end()
#define _str(x) to_string((x))
#define _len(x) int(size((x)))
#define _max(x, y, z) max((x), max((y), (z)))
#define _min(x, y, z) min((x), min((y), (z)))
#define _print_list(list) for (auto x : list) { cout << x << " "; } cout << '\n'
#define _print_grid(grid) for (const auto& v : grid) { for (auto x : v) { cout << x << " "; } cout << '\n'; }
#define _print_map(mp) for (const auto& [ k, v ] : mp) { cout << k << ": " << v << endline; }
#define _lcm(x, y) (((x) * (y)) / __gcd((x), (y)))
#define _index_of(list, x) find(list.begin(), list.end(), (x)) - list.begin()
#define _sublist(list, x, y) decltype(list)(list.begin() + x, list.begin() + y + 1)
#define endline '\n'
#define MULTI_LINE(...) #__VA_ARGS__

constexpr long double PI = 3.14159265358979323846;
constexpr long long int MOD = (long long int)1e9 + 7;
constexpr long double eps = 5e-8;

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

void run(int tc)
{
	int d, n;
	cin >> d >> n;

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

    for (int i = 0; i < n - 1; i++)
    {
        total += d - a[i];
    }

	cout << total << endline;
}

/**
 * Problem Name: 
 * Problem URL: 
 * References 1: 
 *
 * Solution Time Complexity: 
 * Solution Space Complexity: 
 *
 * @author zeus
 */
int main()
{
    _fast_io;
    // _freopen_in;

    int t = 1;
    // cin >> t;

    for (int i = 1; i <= t; i++)
    {
        // cout << "test case: " << i << endline;
        run(i);
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph