Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(void) {
  5.     int n, s[10004], a, b;
  6.  
  7.     freopen("in.txt", "r", stdin);
  8.     for (int te = 1; cin >> n && n; te++) {
  9.         for (int i = 0; i < n; i++) {
  10.             cin >> a >> b;
  11.  
  12.             s[i] = a - b;
  13.         }
  14.  
  15.         int aux = 0, aux2 = 0;
  16.         pair<int, int> ans = { 1, 1 };
  17.  
  18.         for (int i = 0; i < n; i++) {
  19.             int x = aux + s[i];        
  20.             if (x > s[i]) {
  21.                 ans.second++;
  22.                 aux = x;
  23.             }
  24.             else {
  25.                 ans.first = i + 1, ans.second = i + 1;
  26.                 aux = s[i];
  27.             }
  28.             aux2 = max(aux2, aux);
  29.         }
  30.         cout << aux2 << "\n";
  31.         cout << "Teste " << te << "\n";
  32.        
  33.         if (aux2 > 0)
  34.             cout << ans.first << " " << ans.second << "\n\n";
  35.         else
  36.             cout << "nenhum\n\n";
  37.  
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement