QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420209#6532. TradingDJ_FCompile Error//C++141.3kb2024-05-24 15:26:532024-05-24 15:26:56

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 15:26:56]
  • 评测
  • [2024-05-24 15:26:53]
  • 提交

answer

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e5+5;
map<int, bool> mp;
struct note {
    long long v;
    int id;
    friend bool operator < (note x, note y) {
        return x.v<y.v;
    }
};
vector<note> vec;
long long a[N], b[N],v, ans;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t, n, m,id,l=0;
    cin>>t;
    while(t--)
    {
        cin>>n;
        r=n-1;
        ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>v>>id;
            vec.push_back({v,id});
        }
        sort(vec.begin(),vec.end());
//        cout<<vec.front().v<<' '<<vec.front().id;
        while(l<r)
        {
            if(vec[l].id<vec[r].id) {
                ans+=(vec[r].v-vec[l].v)*vec[l].id;
                vec[r].id-=vec[l].id;                
                l++;
            }else if(vec[l].id==vec[r].id) {
                ans+=(vec[r].v-vec[l].v)*vec[l].id;
                r--;l++;
            } else {
                ans+=(vec[r].v-vec[l].v)*vec[r].id;
                vec[l].id-=vec[r].id;
                r--;
            }
        }
        vec.clear();
        cout<<ans<<'\n';
    }
}
/*
for(int i=0;i<n;i++)
8000000000 1000000000000000000
*/

詳細信息

answer.code: In function ‘int main()’:
answer.code:26:9: error: ‘r’ was not declared in this scope
   26 |         r=n-1;
      |         ^