Skip to content

Commit 10a0b6e

Browse files
committed
atCoder 362 3 problem solved
1 parent 7eb6a05 commit 10a0b6e

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

atCoder362/A_Buy_a_Pen.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
////https://atcoder.jp/contests/abc362/tasks/abc362_a
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
typedef long long ll;
5+
const int mod = 1e9 + 7;
6+
const int N = 1e5 + 5;
7+
8+
void solve(){
9+
int r,g,b;cin>>r>>g>>b;
10+
string s;cin>>s;
11+
if(s=="Red"){
12+
cout << min(g,b) <<endl;
13+
}
14+
else if(s=="Green"){
15+
cout << min(r,b)<<endl;
16+
}
17+
else if(s=="Blue"){
18+
cout << min(r,g) <<endl;
19+
}
20+
}
21+
22+
int main() {
23+
ios_base::sync_with_stdio(0);
24+
cin.tie(0);
25+
solve();
26+
}

atCoder362/C_Sum_0.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// ////https://atcoder.jp/contests/abc362/tasks/abc362_c
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
typedef long long ll;
5+
const int mod = 1e9 + 7;
6+
const int N = 1e5 + 5;
7+
8+
void solve() {
9+
int n;
10+
cin >> n;
11+
vector<pair<ll, ll>> ranges(n);
12+
ll minSum = 0, maxSum = 0;
13+
14+
for (int i = 0; i < n; ++i) {
15+
ll L, R;
16+
cin >> L >> R;
17+
ranges[i] = {L, R};
18+
minSum += L;
19+
maxSum += R;
20+
}
21+
22+
// Check if a sum of 0 is possible
23+
if (minSum > 0 || maxSum < 0) {
24+
cout << "No" << endl;
25+
return;
26+
}
27+
28+
// A solution is possible, construct it
29+
cout << "Yes" << endl;
30+
vector<ll> result(n);
31+
ll currentSum = minSum;
32+
33+
// Start with the minimum values
34+
for (int i = 0; i < n; ++i) {
35+
result[i] = ranges[i].first;
36+
}
37+
38+
// Adjust values to make the sum zero
39+
for (int i = 0; i < n && currentSum < 0; ++i) {
40+
ll L = ranges[i].first, R = ranges[i].second;
41+
ll maxIncrease = R - L;
42+
ll increase = min(maxIncrease, -currentSum);
43+
result[i] += increase;
44+
currentSum += increase;
45+
}
46+
47+
for (int i = 0; i < n; ++i) {
48+
cout << result[i] << " ";
49+
}
50+
cout << endl;
51+
}
52+
53+
int main() {
54+
ios_base::sync_with_stdio(0);
55+
cin.tie(0);
56+
solve();
57+
}
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
// void solve(){
82+
// int n;cin>>n;
83+
// vector<ll> v(n);
84+
// bool flag=true;
85+
// for(int i=0;i<n;i++){
86+
// int L1,R1;cin>>L1>>R1;
87+
// if(abs(R1-L1)>1){
88+
// v[i]=L1+1;
89+
// }
90+
// else flag=false;
91+
// }
92+
// if(flag==true){
93+
// cout <<"Yes"<<endl;
94+
// for(int i=0;i<n;i++){
95+
// cout << v[i] <<" ";
96+
// }
97+
// cout <<endl;
98+
// }
99+
// else cout <<"No"<<endl;
100+
// }
101+
102+
// int main() {
103+
// ios_base::sync_with_stdio(0);
104+
// cin.tie(0);
105+
// solve();
106+
// }

0 commit comments

Comments
 (0)