diff options
| author | Omar Magdy <omar.professional8777@gmail.com> | 2022-05-29 23:29:33 +0200 |
|---|---|---|
| committer | Omar Magdy <omar.professional8777@gmail.com> | 2022-05-29 23:29:33 +0200 |
| commit | f5ff62a26052f084b6b807cba220c86785fd45e3 (patch) | |
| tree | 94092ede47f7c36cc18112f48ff861bd6e8e903a /codechef/gasolineIntroudution.cpp | |
| parent | e680d1628e20c0222a83e73695fc0a8857571c63 (diff) | |
| download | competitive-programming-f5ff62a26052f084b6b807cba220c86785fd45e3.tar.xz competitive-programming-f5ff62a26052f084b6b807cba220c86785fd45e3.zip | |
Solved 2 problem and edited .gitignore
Diffstat (limited to 'codechef/gasolineIntroudution.cpp')
| -rw-r--r-- | codechef/gasolineIntroudution.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/codechef/gasolineIntroudution.cpp b/codechef/gasolineIntroudution.cpp new file mode 100644 index 0000000..8c9201d --- /dev/null +++ b/codechef/gasolineIntroudution.cpp @@ -0,0 +1,29 @@ +#include <bits/stdc++.h> + +using namespace std; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + int n; + cin >> n; + vector<int> v(n); + for (int &x : v) + cin >> x; + int sum = v[0]; + int fuel = v[0]; + int i = 1; + while (fuel) { + fuel += v[i]; + sum += v[i]; + if (i == n - 1) + break; + fuel--; + i++; + } + cout << sum << '\n'; + } +} |
