1#include<bits/stdc++.h>
2
3using namespace std;
4
5void testfun(map<string, int> mp){
6 map<string, int>::iterator it = mp.begin();
7 for(; it!=mp.end(); it++){
8 cout<<it->first<<":"<<it->second<<" ";
9 }
10 cout<<endl;
11}
12
13int main()
14{
15 int no, add=0;
16 cin>>no;
17 int var;
18 cin>>var;
19 map<string, int> d, h;
20 h["F"] = 0;
21 while(var--){
22 string naam;
23 int a, b;
24 cin>>naam>>a>>b;
25 d[naam] = b/a;
26 h[naam] = b;
27 add+=b;
28 }
29 cin>>var;
30 while(var--){
31 string naam, c1="", c2="";
32 cin>>naam;
33 int meflux=0;
34 while(meflux<naam.length()){
35 if(naam[meflux]=='_'){
36 c1 = c2;
37 c2 = "";
38 meflux++;
39 continue;
40 }
41 c2+=naam[meflux++];
42 }
43 h[c2]+= h[c1];
44 }
45 //print(days);
46 //print(storage);
47 map<string, int>::reverse_iterator a= d.rbegin();
48 int multiply = 1;
49 for(; a!=d.rend(); a++ ){
50 int temperature = a->second*multiply;
51 if(temperature<no){
52 add+=(h[a->first]*(no-temperature));
53 multiply++;
54 }
55 }
56 cout<<add;
57}
1// C++ program to generate all possible
2// valid IP addresses from given string
3#include <bits/stdc++.h>
4using namespace std;
5
6// Function checks whether IP digits
7// are valid or not.
8int is_valid(string ip)
9{
10 // Splitting by "."
11 vector<string> ips;
12 string ex = "";
13 for (int i = 0; i < ip.size(); i++) {
14 if (ip[i] == '.') {
15 ips.push_back(ex);
16 ex = "";
17 }
18 else {
19 ex = ex + ip[i];
20 }
21 }
22 ips.push_back(ex);
23
24 // Checking for the corner cases
25 // cout << ip << endl;
26 for (int i = 0; i < ips.size(); i++) {
27 // cout << ips[i] <<endl;
28 if (ips[i].length() > 3
29 || stoi(ips[i]) < 0
30 || stoi(ips[i]) > 255)
31 return 0;
32
33 if (ips[i].length() > 1
34 && stoi(ips[i]) == 0)
35 return 0;
36
37 if (ips[i].length() > 1
38 && stoi(ips[i]) != 0
39 && ips[i][0] == '0')
40 return 0;
41 }
42 return 1;
43}
44
45// Function converts string to IP address
46void convert(string ip)
47{
48 int l = ip.length();
49
50 // Check for string size
51 if (l > 12 || l < 4) {
52 cout << "Not Valid IP Address";
53 }
54
55 string check = ip;
56 vector<string> ans;
57
58 // Generating different combinations.
59 for (int i = 1; i < l - 2; i++) {
60 for (int j = i + 1; j < l - 1; j++) {
61 for (int k = j + 1; k < l; k++) {
62 check = check.substr(0, k) + "."
63 + check.substr(k, l - k + 2);
64 check
65 = check.substr(0, j) + "."
66 + check.substr(j, l - j + 3);
67 check
68 = check.substr(0, i) + "."
69 + check.substr(i, l - i + 4);
70
71 // cout<< check <<endl;
72 // Check for the validity of combination
73 if (is_valid(check)) {
74 ans.push_back(check);
75 std::cout << check << '\n';
76 }
77 check = ip;
78 }
79 }
80 }
81}
82
83// Driver code
84int main()
85{
86 string A = "25525511135";
87 string B = "25505011535";
88
89 convert(A);
90 convert(B);
91
92 return 0;
93}
94
95// This code is contributed by Harshit
96
1123456789101112131415161718192021222324252627#include <iostream>#include <bits/stdc++.h>using namespace std;class ABS{ public: void abs(int arr[], int n){ sort(arr, arr+n); int c=0,i; for (i=n-1;i-2>=0;i--){ if (arr[i-2]+arr[i-1]>arr[i]){ c=1; break; } } (c) ? cout<<arr[i-2]<<" "<<arr[i-1]<<" "<<arr[i]<<endl : cout<<-1<<endl;}};int main(){ ABS abx; int arr[] = { 5,4,3,1,2}; int n = sizeof(arr) / sizeof(arr[0]); abx.abs(arr, n); return 0;}X