-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlab_6.cpp
More file actions
60 lines (58 loc) · 1.33 KB
/
lab_6.cpp
File metadata and controls
60 lines (58 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
pair<ll, ll> p;
p = {-1, -1};
ll no_of_queries;
ll no_of_users;
cin >> no_of_users >> no_of_queries;
vector<pair<ll, ll>> v;
int x = 0;
while (no_of_queries--)
{
cin >> x;
if (x == 1)
{
ll userid, amount, i;
cin >> userid >> amount;
if (v.empty())
{
v.push_back({userid, amount});
}
else
{
for (i = 0; i < v.size(); i++)
{
if (userid == v[i].first)
{
v[i].second += amount;
amount=v[i].second;
break;
}
}
if (i == v.size())
{
v.push_back({userid,amount});
}
}
if (amount > p.second)
{
p = {userid,amount};
}
}
else if (x == 2)
{
if (p.first == -1)
{
cout << "No data available\n";
}
else
{
cout << p.first << "\n";
}
}
else cout<<"Invalid input\n";
}
}