Demo entry 5501352

소스

   

Submitted by ㅎㅇ on Jun 28, 2016 at 13:51
Language: C++. Code size: 1.3 kB.

#include <iostream>  
  
using namespace std;  
  
int v[1000002];  
  
int main() {  
    int tc = 0;  
    cin >> tc;  
      
    for (int i = 1; i <= tc; i++) {  
        cout << "Case #" << i << '\n';  
  
        int n = 0, k = 0;  
        for (int jj = 0; jj < 1000002; jj++) {  
            v[jj] = 0;  
        }  
  
        cin >> n;  
        for (int j = 1; j <= n; j++) {  
            cin >> v[j];  
        }  
        cin >> k;  
  
        int res = 0;  
        int cnt = 0;  
        bool flag = false;  
  
        while (1) {  
  
            if (v[res] == v[n]) break;  
              
            int temp = 0;  
            for (int ii = res; ii < n; ii++) {  
                if (v[ii + 1] <= v[res] + k) {  
                    temp = ii + 1;  
                }  
                else {  
                    temp = ii;  
                    break;  
                }  
            }  
  
            if (temp == res) {  
                flag = true;  
                break;  
            }  
            else {  
                cnt++;  
                res = temp;  
            }  
        }  
        if (flag) cout << -1 << '\n';  
        else cout << cnt << '\n';  
    }  
    return 0;  
}  

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).