Submission #896308

#TimeUsernameProblemLanguageResultExecution timeMemory
896308thieunguyenhuyPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
2 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long long, int> pli; typedef pair<int, long long> pil; typedef vector<pair<int, int>> vii; typedef vector<pair<long long, long long>> vll; typedef vector<pair<long long, int>> vli; typedef vector<pair<int, long long>> vil; #define bitcnt(n) __builtin_popcountll((n)) #define BIT(n, i) (((n) >> (i)) & 1ll) #define FLIP(n, i) ((n) ^ (1ll << (i))) #define MASK(i) (1ll << (i)) #define ON(n, i) ((n) | MASK(i)) #define OFF(n, i) ((n) & ~MASK(i)) #define Int __int128 #define gcd(a, b) __gcd(a, b) #define lcm(a, b) a / gcd(a, b) * b #define fi first #define se second template <class T1, class T2> bool maximize(T1 &x, T2 y) { if (x < y) { x = y; return true; } return false; } template <class T1, class T2> bool minimize(T1 &x, T2 y) { if (x > y) { x = y; return true; } return false; } const int N = 1e6 + 5; const int MOD = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18; int n; int a[N], b[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.inp", "r", stdin); freopen("output.out", "w", stdout); #else #define taskname "" if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } #endif cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; } ll ans = 0; for (int i = 1; i <= n; ++i) { if (a[i] >= b[i]) continue; else { for (int l = i - 1, r = i + 1; a[i] < b[i] && l > 0 || r <= n; --l, ++r) { if (l > 0) { int take = min(a[l] - b[l], b[i] - a[i]); ans += take * (i - l); a[l] -= take, a[i] += take; } if (a[i] >= b[i]) break; if (r <= n) { int take = min(a[r], b[i] - a[i]); ans += take * (r - i); a[r] -= take, a[i] += take; } } } } cout << ans; return 0; }

Compilation message (stderr)

bulves.cpp: In function 'int main()':
bulves.cpp:78:56: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   78 |             for (int l = i - 1, r = i + 1; a[i] < b[i] && l > 0 || r <= n; --l, ++r) {
      |                                            ~~~~~~~~~~~~^~~~~~~~
bulves.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen("input.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...