Skip to content

Commit

Permalink
Add Day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchay9 committed Dec 2, 2022
1 parent 5bd3188 commit 503be01
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
28 changes: 28 additions & 0 deletions day1/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;

#define int long long

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif

int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);

string line;

int ans = 0, cur = 0;
while (getline(cin, line)) {
if (line.size()) {
cur += stoll(line);
} else {
ans = max(ans, cur);
cur = 0;
}
}

cout << ans << '\n';
}
40 changes: 40 additions & 0 deletions day1/b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;

#define int long long

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif

int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);

string line;
priority_queue<int, vector<int>, greater<int> > pq;


int cur = 0;
while (getline(cin, line)) {
if (line.size()) {
cur += stoll(line);
} else {
pq.push(cur);
if (pq.size() == 4) pq.pop();

cur = 0;
}
}

pq.push(cur);
if (pq.size() == 4) pq.pop();

int ans = 0;
while (pq.size()) {
ans += pq.top(); pq.pop();
}

cout << ans << '\n';
}

0 comments on commit 503be01

Please sign in to comment.