Skip to content

Instantly share code, notes, and snippets.

@note35
Last active August 29, 2015 14:12
Show Gist options
  • Save note35/09d8882523ad2d1689e9 to your computer and use it in GitHub Desktop.
Save note35/09d8882523ad2d1689e9 to your computer and use it in GitHub Desktop.

Revisions

  1. note35 revised this gist Jan 4, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion p3.cpp
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ int main(void)
    tmp = ans;
    for (it=v.begin(); it!=v.end(); it++)
    {
    offset = -*it + *(it+range);
    offset = *(it+range) - *it;
    if (tmp + offset > ans)
    ans = tmp + offset;
    tmp = tmp + offset;
  2. note35 revised this gist Jan 4, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions p3.cpp
    Original file line number Diff line number Diff line change
    @@ -27,15 +27,15 @@ int main(void)
    cin >> input;
    v.push_back (input);
    if (i<range)
    ans+=input;
    ans += input;
    }

    v.push_back(-1);
    v.push_back (-1);
    tmp = ans;
    for (it=v.begin(); it!=v.end(); it++)
    {
    offset = -*it+*(it+range);
    if (tmp+offset > ans)
    offset = -*it + *(it+range);
    if (tmp + offset > ans)
    ans = tmp + offset;
    tmp = tmp + offset;
    if (*(it+range) == -1)
  3. note35 created this gist Jan 4, 2015.
    25 changes: 25 additions & 0 deletions p1.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /*
    https://www.ptt.cc/bbs/C_Chat/M.1417696853.A.E8F.html
    https://paiza.jp/poh/enkoi
    提出言語:C++
     得点:100 点
     結果:
     テストケース1:success 0.01秒
     テストケース2:success 0.01秒
     テストケース3:success 0.01秒
    */
    #include <iostream>
    using namespace std;
    int main(void)
    {
    int input_n, input, i, ans=0;
    cin >> input_n;
    for (i=0; i<input_n; i++)
    {
    cin >> input;
    ans += input;
    }
    cout << ans << endl;
    return 0;
    }
    26 changes: 26 additions & 0 deletions p2.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    /*
    https://www.ptt.cc/bbs/C_Chat/M.1417696853.A.E8F.html
    https://paiza.jp/poh/enkoi
    提出言語:C++
     得点:100 点
     結果:
     テストケース1:success 0.01秒
     テストケース2:success 0.01秒
     テストケース3:success 0.01秒
    */
    #include <iostream>
    using namespace std;
    int main(void)
    {
    int input_n, input1, input2, input3, i, ans=0;
    cin >> input_n;
    for (i=0; i<input_n; i++)
    {
    cin >> input1 >> input2 >> input3;
    if ((input1 - input2) > 0)
    ans = ans + (input1 - input2)*input3;
    }
    cout << ans << endl;
    return 0;
    }
    46 changes: 46 additions & 0 deletions p3.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    /*
    https://www.ptt.cc/bbs/C_Chat/M.1417696853.A.E8F.html
    https://paiza.jp/poh/enkoi
     提出言語:C++
     得点:100 点
     結果:
     テストケース1:success 0.01秒
     テストケース2:success 0.01秒
     テストケース3:success 0.01秒
     テストケース4:success 0.22秒
     テストケース5:success 0.22秒
    */
    #include <iostream>
    #include <vector>
    using namespace std;
    int main(void)
    {
    int range, input_n;
    int i, input, ans=0, tmp=0, offset;
    vector <int> v;
    vector <int>::iterator it;

    cin >> range >> input_n;
    for (i=0; i<input_n; i++)
    {
    cin >> input;
    v.push_back (input);
    if (i<range)
    ans+=input;
    }

    v.push_back(-1);
    tmp = ans;
    for (it=v.begin(); it!=v.end(); it++)
    {
    offset = -*it+*(it+range);
    if (tmp+offset > ans)
    ans = tmp + offset;
    tmp = tmp + offset;
    if (*(it+range) == -1)
    break;
    }
    cout << ans << endl;
    return 0;
    }