Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 17th, 2012  |  syntax: None  |  size: 0.47 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int a[1000005];
  6.  
  7. int main() {
  8.     ios::sync_with_stdio(false);
  9.     int n;
  10.     while (cin >> n) {
  11.         if (n == 0) break;
  12.         for (int i = 0; i < n; ++i) cin >> a[i];
  13.        
  14.         long long ans = 0;
  15.         for (int i = 1; i < n; ++i) {
  16.             long long z = a[i] - a[i - 1] - 1;
  17.             long long r = min(i, n - i);
  18.             ans += z * r;
  19.         }
  20.         cout << ans << endl;
  21.     }
  22.  
  23.     return 0;
  24. }