Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- ifstream fin("consolidare.in");
- ofstream fout("consolidare.out");
- int32_t main() {
- fin.sync_with_stdio(false);
- fout.sync_with_stdio(false);
- fin.tie(nullptr);
- fout.tie(nullptr);
- int L, H;
- fin >> L >> H;
- vector<vector<bool>> a(H + 1, vector<bool>(L + 1));
- for(int i = 1; i <= L; ++i) {
- int x;
- fin >> x;
- for(int j = H; j > H - x; --j)
- a[j][i] = true;
- }
- int ans = 0;
- for(int i = 1; i <= H; ++i) {
- vector<int> gaps;
- gaps.emplace_back(0);
- for(int j = 1; j <= L; ++j)
- if(!a[i][j])
- ++gaps.back();
- else
- if(gaps.back() > 0)
- gaps.emplace_back(0);
- if(gaps.back() == 0)
- gaps.pop_back();
- int g = 0;
- for(int x : gaps)
- g = __gcd(g, x);
- for(int x : gaps)
- ans += x / g;
- }
- fout << ans;
- }
Add Comment
Please, Sign In to add comment